List of usage examples for org.apache.maven.artifact.versioning VersionRange createFromVersionSpec
public static VersionRange createFromVersionSpec(String spec) throws InvalidVersionSpecificationException
Create a version range from a string representation
Some spec examples are:1.0
Version 1.0[1.0,2.0)
Versions 1.0 (included) to 2.0 (not included)[1.0,2.0]
Versions 1.0 to 2.0 (both included)[1.5,)
Versions 1.5 and higher(,1.0],[1.2,)
Versions up to 1.0 (included) and 1.2 or higherFrom source file:com.github.maven_nar.NarIntegrationTestMojo.java
License:Apache License
private SurefireBooter constructSurefireBooter() throws MojoExecutionException, MojoFailureException { final SurefireBooter surefireBooter = new SurefireBooter(); final Artifact surefireArtifact = (Artifact) this.pluginArtifactMap .get("org.apache.maven.surefire:surefire-booter"); if (surefireArtifact == null) { throw new MojoExecutionException("Unable to locate surefire-booter in the list of plugin artifacts"); }// ww w . j av a 2 s .c o m surefireArtifact.isSnapshot(); // TODO: this is ridiculous, but it fixes // getBaseVersion to be -SNAPSHOT if // needed Artifact junitArtifact; Artifact testNgArtifact; try { addArtifact(surefireBooter, surefireArtifact); junitArtifact = (Artifact) this.projectArtifactMap.get(this.junitArtifactName); // SUREFIRE-378, junit can have an alternate artifact name if (junitArtifact == null && "junit:junit".equals(this.junitArtifactName)) { junitArtifact = (Artifact) this.projectArtifactMap.get("junit:junit-dep"); } // TODO: this is pretty manual, but I'd rather not require the plugin > // dependencies section right now testNgArtifact = (Artifact) this.projectArtifactMap.get(this.testNGArtifactName); if (testNgArtifact != null) { final VersionRange range = VersionRange.createFromVersionSpec("[4.7,)"); if (!range.containsVersion(new DefaultArtifactVersion(testNgArtifact.getVersion()))) { throw new MojoFailureException( "TestNG support requires version 4.7 or above. You have declared version " + testNgArtifact.getVersion()); } convertTestNGParameters(); if (this.testClassesDirectory != null) { this.properties.setProperty("testng.test.classpath", this.testClassesDirectory.getAbsolutePath()); } addArtifact(surefireBooter, testNgArtifact); // The plugin uses a JDK based profile to select the right testng. We // might be explicity using a // different one since its based on the source level, not the JVM. Prune // using the filter. addProvider(surefireBooter, "surefire-testng", surefireArtifact.getBaseVersion(), testNgArtifact); } else if (junitArtifact != null && junitArtifact.getBaseVersion().startsWith("4")) { addProvider(surefireBooter, "surefire-junit4", surefireArtifact.getBaseVersion(), null); } else { // add the JUnit provider as default - it doesn't require JUnit to be // present, // since it supports POJO tests. addProvider(surefireBooter, "surefire-junit", surefireArtifact.getBaseVersion(), null); } } catch (final ArtifactNotFoundException e) { throw new MojoExecutionException( "Unable to locate required surefire provider dependency: " + e.getMessage(), e); } catch (final InvalidVersionSpecificationException e) { throw new MojoExecutionException("Error determining the TestNG version requested: " + e.getMessage(), e); } catch (final ArtifactResolutionException e) { throw new MojoExecutionException("Error to resolving surefire provider dependency: " + e.getMessage(), e); } if (this.suiteXmlFiles != null && this.suiteXmlFiles.length > 0 && this.test == null) { if (testNgArtifact == null) { throw new MojoExecutionException("suiteXmlFiles is configured, but there is no TestNG dependency"); } // TODO: properties should be passed in here too surefireBooter.addTestSuite("org.apache.maven.surefire.testng.TestNGXmlTestSuite", new Object[] { this.suiteXmlFiles, this.testSourceDirectory.getAbsolutePath(), testNgArtifact.getBaseVersion(), testNgArtifact.getClassifier(), this.properties, this.reportsDirectory }); } else { List includeList; List excludeList; if (this.test != null) { // Check to see if we are running a single test. The raw parameter will // come through if it has not been set. // FooTest -> **/FooTest.java includeList = new ArrayList(); excludeList = new ArrayList(); if (this.failIfNoTests == null) { this.failIfNoTests = Boolean.TRUE; } final String[] testRegexes = StringUtils.split(this.test, ","); for (final String testRegexe : testRegexes) { String testRegex = testRegexe; if (testRegex.endsWith(".java")) { testRegex = testRegex.substring(0, testRegex.length() - 5); } // Allow paths delimited by '.' or '/' testRegex = testRegex.replace('.', '/'); includeList.add("**/" + testRegex + ".java"); } } else { includeList = this.includes; excludeList = this.excludes; // defaults here, qdox doesn't like the end javadoc value // Have to wrap in an ArrayList as surefire expects an ArrayList instead // of a List for some reason if (includeList == null || includeList.size() == 0) { includeList = new ArrayList( Arrays.asList(new String[] { "**/Test*.java", "**/*Test.java", "**/*TestCase.java" })); } if (excludeList == null || excludeList.size() == 0) { excludeList = new ArrayList(Arrays.asList(new String[] { "**/*$*" })); } } if (testNgArtifact != null) { surefireBooter.addTestSuite("org.apache.maven.surefire.testng.TestNGDirectoryTestSuite", new Object[] { this.testClassesDirectory, includeList, excludeList, this.testSourceDirectory.getAbsolutePath(), testNgArtifact.getBaseVersion(), testNgArtifact.getClassifier(), this.properties, this.reportsDirectory }); } else { String junitDirectoryTestSuite; if (junitArtifact != null && junitArtifact.getBaseVersion() != null && junitArtifact.getBaseVersion().startsWith("4")) { junitDirectoryTestSuite = "org.apache.maven.surefire.junit4.JUnit4DirectoryTestSuite"; } else { junitDirectoryTestSuite = "org.apache.maven.surefire.junit.JUnitDirectoryTestSuite"; } // fall back to JUnit, which also contains POJO support. Also it can run // classes compiled against JUnit since it has a dependency on JUnit // itself. surefireBooter.addTestSuite(junitDirectoryTestSuite, new Object[] { this.testClassesDirectory, includeList, excludeList }); } } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- getLog().debug("Test Classpath :"); // Check if we need to add configured classes/test classes directories here. // If they are configured, we should remove the default to avoid conflicts. if (!this.project.getBuild().getOutputDirectory().equals(this.classesDirectory.getAbsolutePath())) { this.classpathElements.remove(this.project.getBuild().getOutputDirectory()); this.classpathElements.add(this.classesDirectory.getAbsolutePath()); } if (!this.project.getBuild().getTestOutputDirectory().equals(this.testClassesDirectory.getAbsolutePath())) { this.classpathElements.remove(this.project.getBuild().getTestOutputDirectory()); this.classpathElements.add(this.testClassesDirectory.getAbsolutePath()); } for (final Iterator i = this.classpathElements.iterator(); i.hasNext();) { final String classpathElement = (String) i.next(); getLog().debug(" " + classpathElement); surefireBooter.addClassPathUrl(classpathElement); } final Toolchain tc = getToolchain(); if (tc != null) { getLog().info("Toolchain in surefire-plugin: " + tc); if (ForkConfiguration.FORK_NEVER.equals(this.forkMode)) { this.forkMode = ForkConfiguration.FORK_ONCE; } if (this.jvm != null) { getLog().warn("Toolchains are ignored, 'executable' parameter is set to " + this.jvm); } else { this.jvm = tc.findTool("java"); // NOI18N } } if (this.additionalClasspathElements != null) { for (final Iterator i = this.additionalClasspathElements.iterator(); i.hasNext();) { final String classpathElement = (String) i.next(); getLog().debug(" " + classpathElement); surefireBooter.addClassPathUrl(classpathElement); } } // ---------------------------------------------------------------------- // Forking // ---------------------------------------------------------------------- final ForkConfiguration fork = new ForkConfiguration(); // DUNS if (this.project.getPackaging().equals("nar") || getNarArtifacts().size() > 0) { this.forkMode = "pertest"; } fork.setForkMode(this.forkMode); processSystemProperties(!fork.isForking()); if (getLog().isDebugEnabled()) { showMap(this.systemProperties, "system property"); } if (fork.isForking()) { this.useSystemClassLoader = this.useSystemClassLoader == null ? Boolean.TRUE : this.useSystemClassLoader; fork.setUseSystemClassLoader(this.useSystemClassLoader.booleanValue()); fork.setUseManifestOnlyJar(this.useManifestOnlyJar); fork.setSystemProperties(this.systemProperties); if ("true".equals(this.debugForkedProcess)) { this.debugForkedProcess = "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"; } fork.setDebugLine(this.debugForkedProcess); if (this.jvm == null || "".equals(this.jvm)) { // use the same JVM as the one used to run Maven (the "java.home" one) this.jvm = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; getLog().debug("Using JVM: " + this.jvm); } fork.setJvmExecutable(this.jvm); if (this.workingDirectory != null) { fork.setWorkingDirectory(this.workingDirectory); } else { fork.setWorkingDirectory(this.basedir); } // BEGINDUNS if (this.argLine == null) { this.argLine = ""; } final StringBuffer javaLibraryPath = new StringBuffer(); if (testJNIModule()) { // Add libraries to java.library.path for testing final File jniLibraryPathEntry = getLayout().getLibDirectory(getTargetDirectory(), getMavenProject().getArtifactId(), getMavenProject().getVersion(), getAOL().toString(), Library.JNI); if (jniLibraryPathEntry.exists()) { getLog().debug("Adding library directory to java.library.path: " + jniLibraryPathEntry); if (javaLibraryPath.length() > 0) { javaLibraryPath.append(File.pathSeparator); } javaLibraryPath.append(jniLibraryPathEntry); } final File sharedLibraryPathEntry = getLayout().getLibDirectory(getTargetDirectory(), getMavenProject().getArtifactId(), getMavenProject().getVersion(), getAOL().toString(), Library.SHARED); if (sharedLibraryPathEntry.exists()) { getLog().debug("Adding library directory to java.library.path: " + sharedLibraryPathEntry); if (javaLibraryPath.length() > 0) { javaLibraryPath.append(File.pathSeparator); } javaLibraryPath.append(sharedLibraryPathEntry); } // add jar file to classpath, as one may want to read a // properties file for artifactId and version final String narFile = "target/" + this.project.getArtifactId() + "-" + this.project.getVersion() + ".jar"; getLog().debug("Adding to surefire test classpath: " + narFile); surefireBooter.addClassPathUrl(narFile); } final List dependencies = getNarArtifacts(); // TODO: get seems heavy, not // sure if we can push this // up to before the fork to // use it multiple times. for (final Iterator i = dependencies.iterator(); i.hasNext();) { final NarArtifact dependency = (NarArtifact) i.next(); // FIXME this should be overridable // NarInfo info = dependency.getNarInfo(); // String binding = info.getBinding(getAOL(), Library.STATIC); // NOTE: fixed to shared, jni final String[] bindings = { Library.SHARED, Library.JNI }; for (final String binding2 : bindings) { final String binding = binding2; if (!binding.equals(Library.STATIC)) { final File depLibPathEntry = getLayout().getLibDirectory(getUnpackDirectory(), dependency.getArtifactId(), dependency.getVersion(), getAOL().toString(), binding); if (depLibPathEntry.exists()) { getLog().debug("Adding dependency directory to java.library.path: " + depLibPathEntry); if (javaLibraryPath.length() > 0) { javaLibraryPath.append(File.pathSeparator); } javaLibraryPath.append(depLibPathEntry); } } } } // add final javalibrary path if (javaLibraryPath.length() > 0) { // NOTE java.library.path only works for the jni lib itself, and // not for its dependent shareables. // NOTE: java.library.path does not work with arguments with // spaces as // SureFireBooter splits the line in parts and then quotes // it wrongly NarUtil.addLibraryPathToEnv(javaLibraryPath.toString(), this.environmentVariables, getOS()); } // necessary to find WinSxS if (getOS().equals(OS.WINDOWS)) { this.environmentVariables.put("SystemRoot", NarUtil.getEnv("SystemRoot", "SystemRoot", "C:\\Windows")); } // ENDDUNS fork.setArgLine(this.argLine); fork.setEnvironmentVariables(this.environmentVariables); if (getLog().isDebugEnabled()) { showMap(this.environmentVariables, "environment variable"); fork.setDebug(true); } if (this.argLine != null) { final List args = Arrays.asList(this.argLine.split(" ")); if (args.contains("-da") || args.contains("-disableassertions")) { this.enableAssertions = false; } } } surefireBooter.setFailIfNoTests(this.failIfNoTests == null ? false : this.failIfNoTests.booleanValue()); surefireBooter.setForkedProcessTimeoutInSeconds(this.forkedProcessTimeoutInSeconds); surefireBooter.setRedirectTestOutputToFile(this.redirectTestOutputToFile); surefireBooter.setForkConfiguration(fork); surefireBooter.setChildDelegation(this.childDelegation); surefireBooter.setEnableAssertions(this.enableAssertions); surefireBooter.setReportsDirectory(this.reportsDirectory); addReporters(surefireBooter, fork.isForking()); return surefireBooter; }
From source file:com.github.os72.protocjar.maven.ProtocJarMojo.java
License:Apache License
private File resolveArtifact(String artifactSpec) throws MojoExecutionException { try {/*from ww w.j av a 2 s.c om*/ Properties detectorProps = new Properties(); new PlatformDetector().detect(detectorProps, null); String platform = detectorProps.getProperty("os.detected.classifier"); getLog().info("Resolving artifact: " + artifactSpec + ", platform: " + platform); String[] as = artifactSpec.split(":"); Artifact artifact = artifactFactory.createDependencyArtifact(as[0], as[1], VersionRange.createFromVersionSpec(as[2]), "exe", platform, Artifact.SCOPE_RUNTIME); artifactResolver.resolve(artifact, remoteRepositories, localRepository); File tempFile = File.createTempFile(as[1], ".exe"); copyFile(artifact.getFile(), tempFile); tempFile.setExecutable(true); tempFile.deleteOnExit(); return tempFile; } catch (Exception e) { throw new MojoExecutionException("Error resolving artifact: " + artifactSpec, e); } }
From source file:com.github.panthers.maven.plugins.fromConfig.AbstractFromConfigMojo.java
License:Apache License
/** * Returns the available versions of the artifact of the given range. * Filtered based on configuration//ww w .java 2 s .co m * @param artifactItemsWithRange * @return * @throws MojoExecutionException */ @SuppressWarnings("unchecked") private List<DefaultArtifactVersion> getAvailableVersions(ArtifactItemsWithRange artifactItemsWithRange) throws MojoExecutionException { VersionRange artifactVersionRange; try { artifactVersionRange = VersionRange.createFromVersionSpec(artifactItemsWithRange.getVersionRange()); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException("Version range is invalid."); } Artifact artifact; if (StringUtils.isEmpty(artifactItemsWithRange.getClassifier())) { artifact = factory.createDependencyArtifact(artifactItemsWithRange.getGroupId(), artifactItemsWithRange.getArtifactId(), artifactVersionRange, artifactItemsWithRange.getType(), artifactItemsWithRange.getClassifier(), Artifact.SCOPE_COMPILE); } else { artifact = factory.createDependencyArtifact(artifactItemsWithRange.getGroupId(), artifactItemsWithRange.getArtifactId(), artifactVersionRange, artifactItemsWithRange.getType(), null, Artifact.SCOPE_COMPILE); } List<DefaultArtifactVersion> availableVersions = new ArrayList<DefaultArtifactVersion>(); try { List<DefaultArtifactVersion> allVersions = artifactMetadataSource.retrieveAvailableVersions(artifact, local, remoteRepos); if (artifactItemsWithRange.getIncludeSnapshots()) { availableVersions.addAll(allVersions); getLog().debug("Adding all versions " + allVersions.toString()); } else { Collections.sort(allVersions); Collections.reverse(allVersions); if ("SNAPSHOT".equals(allVersions.get(0).getQualifier()) && artifactItemsWithRange.getIncludeLatestSnapshot()) { //If latest is snapshot and include latest exists add this availableVersions.add(allVersions.get(0)); } else if (!"SNAPSHOT".equals(allVersions.get(0).getQualifier())) { availableVersions.add(allVersions.get(0)); } for (int i = 1; i < allVersions.size(); i++) { //Get all other artifacts without snapshot if (!"SNAPSHOT".equals(allVersions.get(i).getQualifier())) { availableVersions.add(allVersions.get(i)); } } } } catch (ArtifactMetadataRetrievalException e) { throw new MojoExecutionException("Could not retrieve available versions"); } getLog().debug("Final versions to process : " + availableVersions.toString()); return availableVersions; }
From source file:com.github.panthers.maven.plugins.fromConfig.ArtifactItemsWithRange.java
License:Apache License
public ArtifactItemsWithRange(Artifact artifact) throws MojoFailureException { super(artifact); try {//from ww w .j a va 2 s . co m artifact.setVersionRange(VersionRange.createFromVersionSpec(versionRange)); } catch (InvalidVersionSpecificationException e) { throw new MojoFailureException( "Please provide a valid version range." + " check VersionRange JDoc createFromVersionSpec"); } }
From source file:com.github.paulmoloney.maven.plugins.enforcer.AbstractToolChainAwareRule.java
License:Apache License
protected void init(EnforcerRuleHelper helper) throws EnforcerRuleException, MojoExecutionException { final String aVersion = getVersion(); if (null == aVersion || "".equals(aVersion.trim())) { throw new MojoExecutionException("Version parameter was not supplied for rule usage"); }// www. j a va 2 s .com String version = aVersion; try { if (-1 != version.indexOf("${")) { version = (String) helper.evaluate(aVersion); } } catch (ExpressionEvaluationException e) { throw new MojoExecutionException("Unable to evaluate version " + aVersion, e); } try { VersionRange.createFromVersionSpec(version); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException("Invalid version parameter was supplied for rule usage", e); } try { session = (MavenSession) helper.evaluate("${session}"); toolchainManager = (ToolchainManager) helper.getComponent(ToolchainManager.class); outputDirectory = new File((String) helper.evaluate("${project.build.outputDirectory}")); basedir = new File((String) helper.evaluate("${basedir}")); } catch (ExpressionEvaluationException e) { throw new MojoExecutionException("Unable to evaluate maven environment", e); } catch (ComponentLookupException e) { throw new MojoExecutionException("Unable to retrieve component", e); } }
From source file:com.github.spyhunter99.pdf.plugin.PdfMojo.java
License:Apache License
/** * Check the current Maven version to see if it's Maven 3.0 or newer. *//*from ww w .ja v a 2 s . c o m*/ protected static boolean isMaven3OrMore() { try { ArtifactVersion mavenVersion = new DefaultArtifactVersion(getMavenVersion()); return VersionRange.createFromVersionSpec("[3.0,)").containsVersion(mavenVersion); } catch (InvalidVersionSpecificationException e) { return false; } // return new ComparableVersion( getMavenVersion() ).compareTo( new ComparableVersion( "3.0" ) ) >= 0; }
From source file:com.github.wix_maven.LightMojo.java
License:Apache License
/** * Based on Maven-dependency-plugin AbstractFromConfigurationMojo. * //from w w w . ja va2 s . c om * Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved from the dependency list or * from the DependencyManagement section of the pom. * * @param artifactItem * containing information about artifact from plugin configuration. * @return Artifact object representing the specified file. * @throws MojoExecutionException * with a message if the version can't be found in DependencyManagement. */ protected Set<Artifact> getRelatedArtifacts(Artifact artifactItem, String arch, String culture) throws MojoExecutionException { Set<Artifact> artifactSet = new HashSet<Artifact>(); // Map managedVersions = createManagedVersionMap( factory, project.getId(), project.getDependencyManagement() ); VersionRange vr; try { vr = VersionRange.createFromVersionSpec(artifactItem.getVersion()); } catch (InvalidVersionSpecificationException e1) { vr = VersionRange.createFromVersion(artifactItem.getVersion()); } if (PACK_LIB.equalsIgnoreCase(artifactItem.getType()) || PACK_MERGE.equalsIgnoreCase(artifactItem.getType())) { boolean hasSomething = true; // even if this module has culture it's base modules may be neutral try { String classifier = arch + "-" + "neutral"; getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), artifactItem.getType(), artifactSet, vr, classifier); } catch (MojoExecutionException e) { if (culture == null) throw e; hasSomething = false; } if (culture != null) { try { String classifier = arch + "-" + getPrimaryCulture(culture); getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), artifactItem.getType(), artifactSet, vr, classifier); } catch (MojoExecutionException e) { if (hasSomething == false) throw e; } } } // list out all the dependencies with their classifiers // if ("msi".equalsIgnoreCase(artifactItem.getType()) ) { // boolean hasSomething = true; // // even if this module has culture it's base modules may be neutral // try { // String classifier = arch + "-" + "neutral"; // getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), artifactItem.getType(), artifactSet, vr, classifier); // } catch (MojoExecutionException e) { // if (culture == null) // throw e; // hasSomething = false; // } // // if (culture != null) { // try { // String classifier = arch + "-" + getPrimaryCulture(culture); // getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), artifactItem.getType(), artifactSet, vr, classifier); // } catch (MojoExecutionException e) { // if (hasSomething == false) // throw e; // } // } // } // // else if ("nar".equalsIgnoreCase(artifactItem.getType())) { // get one of both 32 & 64 bit... how do we tell whats there to use? // go through nar // for (String arch : getPlatforms()) { // for (String culture : cultures) { // String culture = null; // String classifier = arch + "-" + (culture == null ? "neutral" : culture); // getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), artifactItem.getType(), artifactSet, vr, "x86-Windows-msvc-shared"); // } // } return artifactSet; }
From source file:com.github.wix_maven.PatchMojo.java
License:Apache License
/** * Based on Maven-dependency-plugin AbstractFromConfigurationMojo. * /*www . j a va 2s .c om*/ * Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved from the dependency list or * from the DependencyManagement section of the pom. * * @param artifactItem * containing information about artifact from plugin configuration. * @return Artifact object representing the specified file. * @throws MojoExecutionException * with a message if the version can't be found in DependencyManagement. */ protected Artifact getRelatedArtifact(ArtifactItem artifactItem, String arch, String culture, String type) throws MojoExecutionException { VersionRange vr; try { vr = VersionRange.createFromVersionSpec(artifactItem.getVersion()); } catch (InvalidVersionSpecificationException e1) { vr = VersionRange.createFromVersion(artifactItem.getVersion()); } Set<Artifact> artifactSet = new HashSet<Artifact>(); String classifier = arch + "-" + (culture == null ? "neutral" : getPrimaryCulture(culture)); getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), type, artifactSet, vr, classifier); if (artifactSet.size() != 1) // this is more like an assert - we are only asking for one, and if none it already threw. throw new MojoExecutionException(String.format("Found multiple artifacts for : %1:%2:%3:%4:%5", artifactItem.getGroupId(), artifactItem.getArtifactId(), type, vr, classifier)); return artifactSet.iterator().next(); }
From source file:com.github.wix_maven.UnpackDependenciesMojo.java
License:Apache License
/** * Based on Maven-dependency-plugin AbstractFromConfigurationMojo. * //from w w w . ja va2s . c o m * Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved from the dependency list or * from the DependencyManagement section of the pom. * * @param artifactItem * containing information about artifact from plugin configuration. * @return Artifact object representing the specified file. * @throws MojoExecutionException * with a message if the version can't be found in DependencyManagement. */ protected Set<Artifact> getRelatedArtifacts(Artifact artifactItem) throws MojoExecutionException { Artifact artifact; Set<Artifact> artifactSet = new HashSet<Artifact>(); // Map managedVersions = createManagedVersionMap( factory, project.getId(), project.getDependencyManagement() ); VersionRange vr; try { vr = VersionRange.createFromVersionSpec(artifactItem.getVersion()); } catch (InvalidVersionSpecificationException e1) { // TODO Auto-generated catch block e1.printStackTrace(); vr = VersionRange.createFromVersion(artifactItem.getVersion()); } // if ("msi".equalsIgnoreCase(artifactItem.getType()) || "msp".equalsIgnoreCase(artifactItem.getType()) // || "wixlib".equalsIgnoreCase(artifactItem.getType()) || "msm".equalsIgnoreCase(artifactItem.getType())) { // // artifactItem.getFile().getWixInfo(); // // if (cultures.isEmpty()) // // cultures.add(null); // // // for (String culture : cultures) { // // boolean hasSomething = true; // // even if this module has culture it's base modules may be neutral // try { // String classifier = arch + "-" + "neutral"; // getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), artifactItem.getType(), artifactSet, vr, classifier); // } catch (MojoExecutionException e) { // if (culture == null) // throw e; // hasSomething = false; // } // // if (culture != null) { // try { // String classifier = arch + "-" + getPrimaryCulture(culture); // getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), artifactItem.getType(), artifactSet, vr, classifier); // } catch (MojoExecutionException e) { // if( hasSomething == false ) // throw e; // } // } // // if ("msi".equalsIgnoreCase(artifactItem.getType()) || "msp".equalsIgnoreCase(artifactItem.getType())) { // String classifier = arch + "-" + (culture == null ? "neutral" : getPrimaryCulture(culture) ); // getArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), "wixpdb", artifactSet, vr, classifier); // } // } // if ("nar".equalsIgnoreCase(artifactItem.getType())) { // get one of both 32 & 64 bit... how do we tell whats there to use? // go through nar // for (String arch : getPlatforms()) { // for (String culture : cultures) { // String culture = null; // String classifier = arch + "-" + (culture == null ? "neutral" : culture); // getArtifact(artifactItem, artifactSet, vr, "x86-Windows-msvc-shared"); // } // } return artifactSet; }
From source file:com.github.zhve.ideaplugin.ArtifactDependencyResolver.java
License:Apache License
/** * Convert Dependency to Artifact/* ww w .j a v a 2 s . co m*/ * * @param artifactFactory standard Maven's factory to create artifacts * @param dependency dependency * @return artifact * @throws InvalidVersionSpecificationException if VersionRange is invalid */ private Artifact toDependencyArtifact(ArtifactFactory artifactFactory, Dependency dependency) throws InvalidVersionSpecificationException { // instantiate Artifact dependencyArtifact = artifactFactory.createDependencyArtifact(dependency.getGroupId(), dependency.getArtifactId(), VersionRange.createFromVersionSpec(dependency.getVersion()), dependency.getType(), dependency.getClassifier(), dependency.getScope() == null ? Artifact.SCOPE_COMPILE : dependency.getScope(), null, dependency.isOptional()); // apply exclusions is needed if (!dependency.getExclusions().isEmpty()) { List<String> exclusions = new ArrayList<String>(); for (Exclusion exclusion : dependency.getExclusions()) exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId()); dependencyArtifact.setDependencyFilter(new ExcludesArtifactFilter(exclusions)); } // additional if (Artifact.SCOPE_SYSTEM.equalsIgnoreCase(dependency.getScope())) dependencyArtifact.setFile(new File(dependency.getSystemPath())); return dependencyArtifact; }