Author: fbricon
Date: 2012-05-11 08:11:44 -0400 (Fri, 11 May 2012)
New Revision: 40948
Modified:
branches/jbosstools-3.3.0.Beta3/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/messages.properties
branches/jbosstools-3.3.0.Beta3/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/utils/MavenArtifactHelper.java
Log:
JBIDE-11684 : check enterprise version of jboss spec using a version range (version
containing redhat)
Modified:
branches/jbosstools-3.3.0.Beta3/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/messages.properties
===================================================================
---
branches/jbosstools-3.3.0.Beta3/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/messages.properties 2012-05-11
10:17:09 UTC (rev 40947)
+++
branches/jbosstools-3.3.0.Beta3/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/messages.properties 2012-05-11
12:11:44 UTC (rev 40948)
@@ -5,6 +5,6 @@
ArchetypeExamplesWizardFirstPage_ProjectName_Label=Project name
ArchetypeExamplesWizardFirstPage_Target_Runtime_Label=Target Runtime
ArchetypeExamplesWizardFirstPage_Title=Create a new Java EE project
-ArchetypeExamplesWizardFirstPage_Unresolved_Enterprise_Repo={0} cannot be found. This
indicates you do not have access to a JBoss Enterprise Maven repository.\nThis can cause
build problems. Follow this <a
href\="http\://community.jboss.org/wiki/SettingUpTheJBossEnterpriseR...
for more details.
+ArchetypeExamplesWizardFirstPage_Unresolved_Enterprise_Repo=A *-redhat version of {0}
cannot be found. This indicates you do not have access to a JBoss Enterprise Maven
repository.\nThis can cause build problems. Follow this <a
href\="http\://community.jboss.org/wiki/SettingUpTheJBossEnterpriseR...
for more details.
ArchetypeExamplesWizardFirstPage_Unresolved_WFK_Repo=The enterprise version of this
project has a dependency on {0} which cannot be found. This indicates you do not have
access to a JBoss WFK Maven repository or that repository is incomplete.\nThis can cause
build problems. Follow this <a
href\="http\://community.jboss.org/wiki/SettingUpTheJBossEnterpriseR...
for more details.
ArchetypeExamplesWizardFirstPage_Error_Package=Invalid package name
\ No newline at end of file
Modified:
branches/jbosstools-3.3.0.Beta3/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/utils/MavenArtifactHelper.java
===================================================================
---
branches/jbosstools-3.3.0.Beta3/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/utils/MavenArtifactHelper.java 2012-05-11
10:17:09 UTC (rev 40947)
+++
branches/jbosstools-3.3.0.Beta3/maven/plugins/org.jboss.tools.maven.project.examples/src/org/jboss/tools/maven/project/examples/utils/MavenArtifactHelper.java 2012-05-11
12:11:44 UTC (rev 40948)
@@ -11,14 +11,18 @@
package org.jboss.tools.maven.project.examples.utils;
import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.repository.internal.MavenRepositorySystemSession;
+import org.codehaus.plexus.DefaultPlexusContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
@@ -27,18 +31,27 @@
import org.jboss.tools.maven.project.examples.Messages;
import org.jboss.tools.maven.project.examples.xpl.DependencyKey;
import org.jboss.tools.project.examples.model.ProjectExample;
+import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.repository.LocalRepository;
+import org.sonatype.aether.repository.RemoteRepository;
+import org.sonatype.aether.resolution.VersionRangeRequest;
+import org.sonatype.aether.resolution.VersionRangeResolutionException;
+import org.sonatype.aether.resolution.VersionRangeResult;
+import org.sonatype.aether.util.artifact.DefaultArtifact;
+import org.sonatype.aether.version.Version;
public class MavenArtifactHelper {
- private static final DependencyKey ENTERPRISE_JBOSS_SPEC =
DependencyKey.fromPortableString("org.jboss.spec:jboss-javaee-web-6.0:pom:3.0.0.Beta1-redhat-1::");
//$NON-NLS-1$
+ private static final String JBOSS_SPEC =
"org.jboss.spec:jboss-javaee-web-6.0"; //$NON-NLS-1$
+ private static final String COORDS = JBOSS_SPEC+":[0,)"; //$NON-NLS-1$
/**
* Checks if the EAP repository is available
*
- * @return true if org.jboss.spec:jboss-javaee-web-6.0:pom:3.0.0.Beta1-redhat-1 can be
resolved
+ * @return true if org.jboss.spec:jboss-javaee-web-6.0:pom:*redhat* can be resolved
*/
public static boolean isEnterpriseRepositoryAvailable() {
- boolean isRepoAvailable = isArtifactAvailable(ENTERPRISE_JBOSS_SPEC); //$NON-NLS-1$
+ boolean isRepoAvailable = redHatArtifactExists(COORDS);
return isRepoAvailable;
}
@@ -74,7 +87,7 @@
if (!isEnterpriseRepositoryAvailable()) {
return new Status(IStatus.ERROR,
MavenProjectExamplesActivator.PLUGIN_ID,
- NLS.bind(Messages.ArchetypeExamplesWizardFirstPage_Unresolved_Enterprise_Repo,
ENTERPRISE_JBOSS_SPEC));
+ NLS.bind(Messages.ArchetypeExamplesWizardFirstPage_Unresolved_Enterprise_Repo,
JBOSS_SPEC));
}
if (project != null) {
Set<String> requirements = project.getEssentialEnterpriseDependencyGavs();
@@ -91,4 +104,47 @@
}
return Status.OK_STATUS;
}
+
+ private static boolean redHatArtifactExists(String coords) {
+ RepositorySystem system;
+ try {
+ system = new DefaultPlexusContainer()
+ .lookup(RepositorySystem.class);
+ } catch (Exception e) {
+ MavenProjectExamplesActivator.log(e);
+ return false;
+ }
+ MavenRepositorySystemSession session = new MavenRepositorySystemSession();
+ IMaven maven = MavenPlugin.getMaven();
+ String localRepoHome = maven.getLocalRepositoryPath();
+ LocalRepository localRepo = new LocalRepository(localRepoHome);
+ session.setLocalRepositoryManager(system.newLocalRepositoryManager(localRepo));
+
+ VersionRangeRequest rangeRequest = new VersionRangeRequest();
+ rangeRequest.setArtifact( new DefaultArtifact(coords));
+
+ List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>();
+ try {
+ repos.addAll(maven.getArtifactRepositories(false));
+ } catch (CoreException e) {
+ MavenProjectExamplesActivator.log(e);
+ return false;
+ }
+ for (ArtifactRepository repo : repos) {
+ RemoteRepository remoteRepo = new RemoteRepository(repo.getId(), "default",
repo.getUrl()); //$NON-NLS-1$
+ rangeRequest.addRepository(remoteRepo);
+ }
+ try {
+ VersionRangeResult result = system.resolveVersionRange( session, rangeRequest);
+ List<Version> versions = result.getVersions();
+ for (Version version:versions) {
+ if (version != null && version.toString().contains("redhat")) {
//$NON-NLS-1$
+ return true;
+ }
+ }
+ } catch (VersionRangeResolutionException e) {
+ MavenProjectExamplesActivator.log(e);
+ }
+ return false;
+ }
}