List of usage examples for org.apache.maven.artifact Artifact SCOPE_COMPILE
String SCOPE_COMPILE
To view the source code for org.apache.maven.artifact Artifact SCOPE_COMPILE.
Click Source Link
From source file:at.yawk.mdep.GenerateMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (cacheHours > 0) { cacheStore = Environment.createCacheStore(new Logger() { @Override//from w w w .j a va 2s .c o m public void info(String msg) { getLog().info(msg); } @Override public void warn(String msg) { getLog().warn(msg); } }, "mdep-maven-plugin"); } ArtifactMatcher includesMatcher; if (includes == null) { includesMatcher = ArtifactMatcher.acceptAll(); } else { includesMatcher = ArtifactMatcher.anyMatch(toAntMatchers(includes)); } ArtifactMatcher excludesMatcher = ArtifactMatcher.anyMatch(toAntMatchers(excludes)); ArtifactMatcher matcher = includesMatcher.and(excludesMatcher.not()); List<Artifact> artifacts = new ArrayList<>(); try { ArtifactFilter subtreeFilter = artifact -> artifact.getScope() == null || artifact.getScope().equals(Artifact.SCOPE_COMPILE) || artifact.getScope().equals(Artifact.SCOPE_RUNTIME); DependencyNode root = dependencyTreeBuilder.buildDependencyTree(project, localRepository, subtreeFilter); root.accept(new DependencyNodeVisitor() { @Override public boolean visit(DependencyNode node) { if (node.getArtifact() != null) { if (!subtreeFilter.include(node.getArtifact())) { return false; } artifacts.add(node.getArtifact()); } return true; } @Override public boolean endVisit(DependencyNode node) { return true; } }); } catch (DependencyTreeBuilderException e) { throw new MojoExecutionException("Failed to build dependency tree", e); } List<Dependency> dependencies = new ArrayList<>(); for (Artifact artifact : artifacts) { if (matcher.matches(artifact)) { dependencies.add(findArtifact(artifact)); } } getLog().info("Saving dependency xml"); DependencySet dependencySet = new DependencySet(); dependencySet.setDependencies(dependencies); if (!outputDirectory.mkdirs()) { throw new MojoExecutionException("Failed to create output directory"); } File outputFile = new File(outputDirectory, "mdep-dependencies.xml"); try { JAXBContext jaxbContext = JAXBContext.newInstance(DependencySet.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(dependencySet, outputFile); } catch (JAXBException e) { throw new MojoExecutionException("Failed to serialize dependency set", e); } Resource resource = new Resource(); resource.setDirectory(outputDirectory.toString()); resource.setFiltering(false); project.addResource(resource); }
From source file:be.fedict.eid.applet.maven.sql.ddl.SQLDDLMojo.java
License:Open Source License
@Override public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("SQL DDL script generator"); File outputFile = new File(this.outputDirectory, this.outputName); getLog().info("Output SQL DDL script file: " + outputFile.getAbsolutePath()); this.outputDirectory.mkdirs(); try {/*from www . j a v a2 s . c om*/ outputFile.createNewFile(); } catch (IOException e) { throw new MojoExecutionException("I/O error.", e); } for (ArtifactItem artifactItem : this.artifactItems) { getLog().info("artifact: " + artifactItem.getGroupId() + ":" + artifactItem.getArtifactId()); List<Dependency> dependencies = this.project.getDependencies(); String version = null; for (Dependency dependency : dependencies) { if (StringUtils.equals(dependency.getArtifactId(), artifactItem.getArtifactId()) && StringUtils.equals(dependency.getGroupId(), artifactItem.getGroupId())) { version = dependency.getVersion(); break; } } getLog().info("artifact version: " + version); VersionRange versionRange = VersionRange.createFromVersion(version); Artifact artifact = this.artifactFactory.createDependencyArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), versionRange, "jar", null, Artifact.SCOPE_COMPILE); try { this.resolver.resolve(artifact, this.remoteRepos, this.local); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to resolve artifact.", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to find artifact.", e); } getLog().info("artifact file: " + artifact.getFile().getAbsolutePath()); getLog().info("hibernate dialect: " + this.hibernateDialect); URL artifactUrl; try { artifactUrl = artifact.getFile().toURI().toURL(); } catch (MalformedURLException e) { throw new MojoExecutionException("URL error.", e); } URLClassLoader classLoader = new URLClassLoader(new URL[] { artifactUrl }, this.getClass().getClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); AnnotationDB annotationDb = new AnnotationDB(); try { annotationDb.scanArchives(artifactUrl); } catch (IOException e) { throw new MojoExecutionException("I/O error.", e); } Set<String> classNames = annotationDb.getAnnotationIndex().get(Entity.class.getName()); getLog().info("# JPA entity classes: " + classNames.size()); AnnotationConfiguration configuration = new AnnotationConfiguration(); configuration.setProperty("hibernate.dialect", this.hibernateDialect); Dialect dialect = Dialect.getDialect(configuration.getProperties()); getLog().info("dialect: " + dialect.toString()); for (String className : classNames) { getLog().info("JPA entity: " + className); Class<?> entityClass; try { entityClass = classLoader.loadClass(className); getLog().info("entity class loader: " + entityClass.getClassLoader()); } catch (ClassNotFoundException e) { throw new MojoExecutionException("class not found.", e); } configuration.addAnnotatedClass(entityClass); } SchemaExport schemaExport = new SchemaExport(configuration); schemaExport.setFormat(true); schemaExport.setHaltOnError(true); schemaExport.setOutputFile(outputFile.getAbsolutePath()); schemaExport.setDelimiter(";"); try { getLog().info("SQL DDL script: " + IOUtil.toString(new FileInputStream(outputFile))); } catch (FileNotFoundException e) { throw new MojoExecutionException("file not found.", e); } catch (IOException e) { throw new MojoExecutionException("I/O error.", e); } // operate schemaExport.execute(true, false, false, true); List<Exception> exceptions = schemaExport.getExceptions(); for (Exception exception : exceptions) { getLog().error("exception: " + exception.getMessage()); } } }
From source file:com.adviser.maven.GraphArtifactCollector.java
License:Apache License
private void checkScopeUpdate(ResolutionNode farthest, ResolutionNode nearest, List listeners) { boolean updateScope = false; Artifact farthestArtifact = farthest.getArtifact(); Artifact nearestArtifact = nearest.getArtifact(); if (Artifact.SCOPE_RUNTIME.equals(farthestArtifact.getScope()) && (Artifact.SCOPE_TEST.equals(nearestArtifact.getScope()) || Artifact.SCOPE_PROVIDED.equals(nearestArtifact.getScope()))) { updateScope = true;// ww w . j a va 2 s. com } if (Artifact.SCOPE_COMPILE.equals(farthestArtifact.getScope()) && !Artifact.SCOPE_COMPILE.equals(nearestArtifact.getScope())) { updateScope = true; } // current POM rules all if (nearest.getDepth() < 2 && updateScope) { updateScope = false; fireEvent(ResolutionListener.UPDATE_SCOPE_CURRENT_POM, listeners, nearest, farthestArtifact); } if (updateScope) { fireEvent(ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthestArtifact); // previously we cloned the artifact, but it is more effecient to // just update the scope // if problems are later discovered that the original object needs // its original scope value, cloning may // again be appropriate nearestArtifact.setScope(farthestArtifact.getScope()); } }
From source file:com.akathist.maven.plugins.launch4j.ClassPath.java
License:Open Source License
net.sf.launch4j.config.ClassPath toL4j(Set dependencies) { net.sf.launch4j.config.ClassPath ret = new net.sf.launch4j.config.ClassPath(); ret.setMainClass(mainClass);//from w ww. java2 s.c o m List cp = new ArrayList(); if (preCp != null) addToCp(cp, preCp); if (addDependencies) { if (jarLocation == null) jarLocation = ""; else if (!jarLocation.endsWith("/")) jarLocation += "/"; Iterator i = dependencies.iterator(); while (i.hasNext()) { Artifact dep = (Artifact) i.next(); if (Artifact.SCOPE_COMPILE.equals(dep.getScope()) || Artifact.SCOPE_RUNTIME.equals(dep.getScope())) { String depFilename; depFilename = dep.getFile().getName(); // System.out.println("dep = " + depFilename); cp.add(jarLocation + depFilename); } } } if (postCp != null) addToCp(cp, postCp); ret.setPaths(cp); return ret; }
From source file:com.alibaba.citrus.maven.eclipse.base.ide.AbstractIdeSupportMojo.java
License:Apache License
/** * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with * the <code>resolved</code> property set to true. * * @return list of projects artifacts//from w w w . j a v a2 s . c om * @throws MojoExecutionException if unable to parse dependency versions */ private Set getProjectArtifacts() throws MojoExecutionException { // [MECLIPSE-388] Don't sort this, the order should be identical to getProject.getDependencies() Set artifacts = new LinkedHashSet(); for (Iterator dependencies = getProject().getDependencies().iterator(); dependencies.hasNext();) { Dependency dependency = (Dependency) dependencies.next(); String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); VersionRange versionRange; try { versionRange = VersionRange.createFromVersionSpec(dependency.getVersion()); } catch (InvalidVersionSpecificationException e) { throw new MojoExecutionException(Messages.getString("AbstractIdeSupportMojo.unabletoparseversion", //$NON-NLS-1$ new Object[] { dependency.getArtifactId(), dependency.getVersion(), dependency.getManagementKey(), e.getMessage() }), e); } String type = dependency.getType(); if (type == null) { type = Constants.PROJECT_PACKAGING_JAR; } String classifier = dependency.getClassifier(); boolean optional = dependency.isOptional(); String scope = dependency.getScope(); if (scope == null) { scope = Artifact.SCOPE_COMPILE; } Artifact art = getArtifactFactory().createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, optional); if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) { art.setFile(new File(dependency.getSystemPath())); } handleExclusions(art, dependency); artifacts.add(art); } return artifacts; }
From source file:com.basistech.bbhmp.RosapiBundleCollectorMojo.java
License:Open Source License
private Artifact getArtifact(BundleInfo bundle) throws MojoExecutionException, MojoFailureException { Artifact artifact;//from w w w . j av a2s .c om /* * Anything in the gav may be interpolated. * Version may be "-dependency-" to look for the artifact as a dependency. */ String gav = interpolator.interpolate(bundle.gav); String[] pieces = gav.split("/"); String groupId = pieces[0]; String artifactId = pieces[1]; String versionStr; String classifier = null; if (pieces.length == 3) { versionStr = pieces[2]; } else { classifier = pieces[2]; versionStr = pieces[3]; } if ("-dependency-".equals(versionStr)) { versionStr = getArtifactVersionFromDependencies(groupId, artifactId); if (versionStr == null) { throw new MojoFailureException(String.format( "Request for %s:%s as a dependency, but it is not a dependency", groupId, artifactId)); } } VersionRange vr; try { vr = VersionRange.createFromVersionSpec(versionStr); } catch (InvalidVersionSpecificationException e1) { throw new MojoExecutionException("Bad version range " + versionStr, e1); } artifact = factory.createDependencyArtifact(groupId, artifactId, vr, "jar", classifier, Artifact.SCOPE_COMPILE); // Maven 3 will search the reactor for the artifact but Maven 2 does not // to keep consistent behaviour, we search the reactor ourselves. Artifact result = getArtifactFomReactor(artifact); if (result != null) { return result; } try { resolver.resolve(artifact, remoteRepos, local); } catch (ArtifactResolutionException e) { throw new MojoExecutionException("Unable to resolve artifact.", e); } catch (ArtifactNotFoundException e) { throw new MojoExecutionException("Unable to find artifact.", e); } return artifact; }
From source file:com.coderplus.apacheutils.translators.ClassifierTypeTranslator.java
License:Apache License
public Set<Artifact> translate(Set<Artifact> artifacts) { Set<Artifact> results;/*from w w w. ja va 2 s .c o m*/ results = new HashSet<Artifact>(); for (Artifact artifact : artifacts) { // this translator must pass both type and classifier here so we // will use the // base artifact value if null comes in String useType; if (StringUtils.isNotEmpty(this.type)) { useType = this.type; } else { useType = artifact.getType(); } String useClassifier; if (StringUtils.isNotEmpty(this.classifier)) { useClassifier = this.classifier; } else { useClassifier = artifact.getClassifier(); } // Create a new artifact Artifact newArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), Artifact.SCOPE_COMPILE, useType, useClassifier, new DefaultArtifactHandler(useType)); // note the new artifacts will always have the scope set to null. We // should // reset it here so that it will pass other filters if needed newArtifact.setScope(artifact.getScope()); results.add(newArtifact); } return results; }
From source file:com.dooioo.se.lorik.apidoclet.maven.plugin.JavadocUtil.java
License:Apache License
/** * Copy from {@link org.apache.maven.project.MavenProject#getCompileArtifacts()} * @param artifacts not null//from w w w.ja v a 2s .c om * @param withTestScope flag to include or not the artifacts with test scope * @return list of compile artifacts with or without test scope. */ protected static List<Artifact> getCompileArtifacts(Set<Artifact> artifacts, boolean withTestScope) { List<Artifact> list = new ArrayList<Artifact>(artifacts.size()); for (Artifact a : artifacts) { // TODO: classpath check doesn't belong here - that's the other method if (a.getArtifactHandler().isAddedToClasspath()) { // TODO: let the scope handler deal with this if (withTestScope) { if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope()) || Artifact.SCOPE_TEST.equals(a.getScope())) { list.add(a); } } else { if (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_PROVIDED.equals(a.getScope()) || Artifact.SCOPE_SYSTEM.equals(a.getScope())) { list.add(a); } } } } return list; }
From source file:com.evolveum.midpoint.tools.schemadist.SchemaDistMojo.java
License:Apache License
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException, InvalidVersionSpecificationException { Artifact artifact;// ww w . j a v a2 s . c om VersionRange vr = VersionRange.createFromVersionSpec(artifactItem.getVersion()); if (StringUtils.isEmpty(artifactItem.getClassifier())) { artifact = factory.createDependencyArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), vr, artifactItem.getType(), null, Artifact.SCOPE_COMPILE); } else { artifact = factory.createDependencyArtifact(artifactItem.getGroupId(), artifactItem.getArtifactId(), vr, artifactItem.getType(), artifactItem.getClassifier(), Artifact.SCOPE_COMPILE); } try { resolver.resolve(artifact, remoteRepos, local); } catch (ArtifactResolutionException | ArtifactNotFoundException e) { throw new MojoExecutionException("Error resolving artifact " + artifact, e); } return artifact; }
From source file:com.fizzed.stork.maven.AssemblyMojo.java
public List<Artifact> artifactsToStage() { List<Artifact> artifacts = new ArrayList<Artifact>(); // include project artifact? if (!shouldArtifactBeStaged(project.getArtifact())) { getLog().info("Project artifact may have a classifier or is not of type jar (will not be staged)"); } else {/*from ww w .j a va 2s . c o m*/ artifacts.add(project.getArtifact()); } // any additional artifacts attached to this project? for (Artifact a : project.getAttachedArtifacts()) { if (shouldArtifactBeStaged(a)) { artifacts.add(a); } } // get resolved artifacts as well for (Artifact a : project.getArtifacts()) { if (a.getArtifactHandler().isAddedToClasspath() && (Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()))) { artifacts.add(a); } } return artifacts; }