Java Code Examples for org.apache.maven.artifact.Artifact

The following examples show how to use org.apache.maven.artifact.Artifact. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: javafx-maven-plugin   Source File: JavaFXRunMojoTestCase.java    License: Apache License 2.0 6 votes vote down vote up
protected JavaFXRunMojo getJavaFXRunMojo(String parent) throws Exception {
    File testPom = new File(getBasedir(), parent + "/pom.xml");
    JavaFXRunMojo mojo = (JavaFXRunMojo) lookupMojo("run", testPom);
    assertNotNull(mojo);

    setUpProject(testPom, mojo);
    MavenProject project = (MavenProject) getVariableValueFromObject( mojo, "project" );
    assertNotNull(project);

    if (! project.getDependencies().isEmpty()) {
        final MavenArtifactResolver resolver = new MavenArtifactResolver(project.getRepositories());
        Set<Artifact> artifacts = project.getDependencies().stream()
                .map(d -> new DefaultArtifact(d.getGroupId(), d.getArtifactId(), d.getClassifier(), d.getType(), d.getVersion()))
                .flatMap(a -> resolver.resolve(a).stream())
                .collect(Collectors.toSet());
        if (artifacts != null) {
            project.setArtifacts(artifacts);
        }
    }
    setVariableValueToObject(mojo, "compilePath", project.getCompileClasspathElements());
    setVariableValueToObject(mojo, "session", session);
    setVariableValueToObject(mojo, "executable", "java");
    setVariableValueToObject(mojo, "basedir", new File(getBasedir(), parent));

    return mojo;
}
 
Example 2
Source Project: jax-maven-plugin   Source File: Util.java    License: Apache License 2.0 6 votes vote down vote up
static Stream<String> getPluginRuntimeDependencyEntries(AbstractMojo mojo, MavenProject project, Log log,
        RepositorySystem repositorySystem, ArtifactRepository localRepository,
        List<ArtifactRepository> remoteRepositories) {
    PluginDescriptor pluginDescriptor = (PluginDescriptor) mojo.getPluginContext().get(PLUGIN_DESCRIPTOR);
    Plugin plugin = project.getBuild().getPluginsAsMap().get(pluginDescriptor.getPluginLookupKey());

    List<ArtifactResolutionResult> artifactResolutionResults = plugin //
            .getDependencies() //
            .stream() //
            .map(repositorySystem::createDependencyArtifact) //
            .map(a -> Util.resolve(log, a, repositorySystem, localRepository, remoteRepositories)) //
            .collect(Collectors.toList());

    Stream<Artifact> originalArtifacts = artifactResolutionResults.stream()
            .map(ArtifactResolutionResult::getOriginatingArtifact);

    Stream<Artifact> childArtifacts = artifactResolutionResults.stream()
            .flatMap(resolutionResult -> resolutionResult.getArtifactResolutionNodes().stream())
            .map(ResolutionNode::getArtifact);

    return Stream.concat(originalArtifacts, childArtifacts).map(Artifact::getFile).map(File::getAbsolutePath);
}
 
Example 3
Source Project: camel-spring-boot   Source File: SpringBootStarterMojo.java    License: Apache License 2.0 6 votes vote down vote up
private Set<String> filterIncludedArtifacts(Set<String> artifacts) {

        Set<Artifact> dependencies;
        try {
            Artifact artifact = project.getArtifactMap().get(getMainDepGroupId() + ":" + getMainDepArtifactId());
            ProjectBuildingResult result = projectBuilder.build(artifact, project.getProjectBuildingRequest());
            MavenProject prj = result.getProject();
            prj.setRemoteArtifactRepositories(project.getRemoteArtifactRepositories());
            dependencies = projectDependenciesResolver.resolve(prj, Collections.singleton(Artifact.SCOPE_COMPILE), session);
        } catch (Exception e) {
            throw new RuntimeException("Unable to build project dependency tree", e);
        }

        Set<String> included = new TreeSet<>();
        dependencies.stream()
                .filter(a -> !Artifact.SCOPE_TEST.equals(a.getScope()))
                .map(a -> a.getGroupId() + ":" + a.getArtifactId())
                .forEach(included::add);
        included.retainAll(artifacts);

        return included;
    }
 
Example 4
Source Project: sarl   Source File: MavenHelper.java    License: Apache License 2.0 6 votes vote down vote up
/** Resolve the artifacts with the given key.
 *
 * @param groupId the group identifier.
 * @param artifactId the artifact identifier.
 * @return the discovered artifacts.
 * @throws MojoExecutionException if resolution cannot be done.
 * @since 0.8
 */
public Set<Artifact> resolve(String groupId, String artifactId) throws MojoExecutionException {
	final ArtifactResolutionRequest request = new ArtifactResolutionRequest();
	request.setResolveRoot(true);
	request.setResolveTransitively(true);
	request.setLocalRepository(getSession().getLocalRepository());
	request.setRemoteRepositories(getSession().getCurrentProject().getRemoteArtifactRepositories());
	request.setOffline(getSession().isOffline());
	request.setForceUpdate(getSession().getRequest().isUpdateSnapshots());
	request.setServers(getSession().getRequest().getServers());
	request.setMirrors(getSession().getRequest().getMirrors());
	request.setProxies(getSession().getRequest().getProxies());
	request.setArtifact(createArtifact(groupId, artifactId));

	final ArtifactResolutionResult result = resolve(request);

	return result.getArtifacts();
}
 
Example 5
Source Project: netbeans   Source File: EarImpl.java    License: Apache License 2.0 6 votes vote down vote up
private EarImpl.MavenModule findMavenModule(Artifact art, EarImpl.MavenModule[] mm) {
    EarImpl.MavenModule toRet = null;
    for (EarImpl.MavenModule m : mm) {
        if (art.getGroupId().equals(m.groupId) && art.getArtifactId().equals(m.artifactId)) {
            m.artifact = art;
            toRet = m;
            break;
        }
    }
    if (toRet == null) {
        toRet = new EarImpl.MavenModule();
        toRet.artifact = art;
        toRet.groupId = art.getGroupId();
        toRet.artifactId = art.getArtifactId();
        toRet.classifier = art.getClassifier();
        //add type as well?
    }
    return toRet;
}
 
Example 6
Source Project: kogito-runtimes   Source File: AbstractKieMojo.java    License: Apache License 2.0 6 votes vote down vote up
protected boolean hasClassOnClasspath(MavenProject project, String className) {
    try {
        Set<Artifact> elements = project.getArtifacts();
        URL[] urls = new URL[elements.size()];

        int i = 0;
        Iterator<Artifact> it = elements.iterator();
        while (it.hasNext()) {
            Artifact artifact = it.next();

            urls[i] = artifact.getFile().toURI().toURL();
            i++;
        }
        try (URLClassLoader cl = new URLClassLoader(urls)) {
            cl.loadClass(className);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example 7
Source Project: webstart   Source File: DefaultJnlpDependencyRequestBuilder.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public JnlpDependencyRequest createRequest( Artifact artifact, boolean outputJarVersion, boolean useUniqueVersions )
{

    if ( globalConfig == null )
    {
        throw new IllegalStateException( "No config found, use init method before creating a request" );
    }

    JnlpDependencyConfig config = createConfig( artifact, outputJarVersion, useUniqueVersions );

    JnlpDependencyTask[] tasks = createTasks( config );

    JnlpDependencyRequest request = new JnlpDependencyRequest( config, tasks );
    return request;
}
 
Example 8
private static File getClasspathElement(Artifact artifact, MavenProject mavenProject)
                                                                                     throws MojoExecutionException {
    if (artifact.getClassifier() != null) {
        return artifact.getFile();
    }
    String refId = artifact.getGroupId() + ":" + artifact.getArtifactId();
    MavenProject project = (MavenProject) mavenProject.getProjectReferences().get(refId);
    if (project != null) {
        return new File(project.getBuild().getOutputDirectory());
    } else {
        File file = artifact.getFile();
        if ((file == null) || (!file.exists())) {
            throw new MojoExecutionException("Dependency Resolution Required " + artifact);
        }
        return file;
    }
}
 
Example 9
Source Project: botsing   Source File: BotsingMojo.java    License: Apache License 2.0 6 votes vote down vote up
public List<Artifact> getDependencyTree(DependencyInputType dependencyType) throws MojoExecutionException {
	try {
		ProjectBuildingRequest buildingRequest = getProjectbuildingRequest(dependencyType);

		// TODO check if it is necessary to specify an artifact filter
		DependencyNode rootNode = dependencyGraphBuilder.buildDependencyGraph(buildingRequest, null,
				reactorProjects);

		List<Artifact> artifactList = new ArrayList<Artifact>();
		addChildDependencies(rootNode, artifactList);

		return artifactList;

	} catch (DependencyGraphBuilderException e) {
		throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
	}
}
 
Example 10
Source Project: vertx-maven-plugin   Source File: AbstractVertxMojo.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * this method helps in resolving the {@link Artifact} as maven coordinates
 * coordinates ::= group:artifact[:packaging[:classifier]]:version
 *
 * @param artifact - the artifact which need to be represented as maven coordinate
 * @return string representing the maven coordinate
 */
protected String asMavenCoordinates(Artifact artifact) {
    // TODO-ROL: Shouldn't there be also the classified included after the groupId (if given ?)
    // Maybe we we should simply reuse DefaultArtifact.toString() (but could be too fragile as it might change
    // although I don't think it will change any time soon since probably many people already
    // rely on it)
    StringBuilder artifactCords = new StringBuilder().
        append(artifact.getGroupId())
        .append(":")
        .append(artifact.getArtifactId());
    if (!"jar".equals(artifact.getType()) || artifact.hasClassifier()) {
        artifactCords.append(":").append(artifact.getType());
    }
    if (artifact.hasClassifier()) {
        artifactCords.append(":").append(artifact.getClassifier());
    }
    artifactCords.append(":").append(artifact.getVersion());
    return artifactCords.toString();
}
 
Example 11
private Artifact getScalaScoverageRuntimeArtifact( String scalaMainVersion )
    throws ArtifactNotFoundException, ArtifactResolutionException
{
    Artifact result = null;

    String resolvedScalacRuntimeVersion = scalacPluginVersion;
    if ( resolvedScalacRuntimeVersion == null || "".equals( resolvedScalacRuntimeVersion ) )
    {
        for ( Artifact artifact : pluginArtifacts )
        {
            if ( "org.scoverage".equals( artifact.getGroupId() )
                && "scalac-scoverage-plugin_2.12".equals( artifact.getArtifactId() ) )
            {
                resolvedScalacRuntimeVersion = artifact.getVersion();
                break;
            }
        }
    }

    result =
        getResolvedArtifact( "org.scoverage", "scalac-scoverage-runtime_" + scalaMainVersion,
                             resolvedScalacRuntimeVersion );
    return result;
}
 
Example 12
Source Project: appassembler   Source File: AbstractScriptGeneratorMojo.java    License: MIT License 6 votes vote down vote up
protected void installDependencies( final String outputDirectory, final String repositoryName )
    throws MojoExecutionException, MojoFailureException
{
    if ( generateRepository )
    {
        // The repo where the jar files will be installed
        ArtifactRepository artifactRepository =
            artifactRepositoryFactory.createDeploymentArtifactRepository( "appassembler", "file://"
                + outputDirectory + "/" + repositoryName, getArtifactRepositoryLayout(), false );

        for ( Artifact artifact : artifacts )
        {
            installArtifact( artifact, artifactRepository, this.useTimestampInSnapshotFileName );
        }

        // install the project's artifact in the new repository
        installArtifact( projectArtifact, artifactRepository );
    }
}
 
Example 13
Source Project: java-specialagent   Source File: MutableMojo.java    License: Apache License 2.0 6 votes vote down vote up
static void resolveDependencies(final MavenSession session, final MojoExecution execution, final MojoExecutor executor, final ProjectDependenciesResolver projectDependenciesResolver) throws DependencyResolutionException, LifecycleExecutionException {
//    flushProjectArtifactsCache(executor);

    final MavenProject project = session.getCurrentProject();
    final Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
    final Map<String,List<MojoExecution>> executions = new LinkedHashMap<>(execution.getForkedExecutions());
    final ExecutionListener executionListener = session.getRequest().getExecutionListener();
    try {
      project.setDependencyArtifacts(null);
      execution.getForkedExecutions().clear();
      session.getRequest().setExecutionListener(null);
      executor.execute(session, Collections.singletonList(execution), new ProjectIndex(session.getProjects()));
    }
    finally {
      execution.getForkedExecutions().putAll(executions);
      session.getRequest().setExecutionListener(executionListener);
      project.setDependencyArtifacts(dependencyArtifacts);
    }

    projectDependenciesResolver.resolve(newDefaultDependencyResolutionRequest(session));
  }
 
Example 14
Source Project: webstart   Source File: AbstractJnlpMojo.java    License: MIT License 6 votes vote down vote up
/**
 * @param pattern   pattern to test over artifacts
 * @param artifacts collection of artifacts to check
 * @return true if filter matches no artifact, false otherwise *
 */
private boolean ensurePatternMatchesAtLeastOneArtifact( String pattern, Collection<Artifact> artifacts )
{
    List<String> onePatternList = new ArrayList<>();
    onePatternList.add( pattern );
    ArtifactFilter filter = new IncludesArtifactFilter( onePatternList );

    boolean noMatch = true;
    for ( Artifact artifact : artifacts )
    {
        getLog().debug( "checking pattern: " + pattern + " against " + artifact );

        if ( filter.include( artifact ) )
        {
            noMatch = false;
            break;
        }
    }
    if ( noMatch )
    {
        getLog().error( "pattern: " + pattern + " doesn't match any artifact." );
    }
    return noMatch;
}
 
Example 15
Source Project: ci.maven   Source File: DeployMojo.java    License: Apache License 2.0 5 votes vote down vote up
protected void installDependencies() throws Exception {
    Set<Artifact> artifacts = project.getArtifacts();
    log.debug("Number of compile dependencies for " + project.getArtifactId() + " : " + artifacts.size());
    
    for (Artifact artifact : artifacts) {
        // skip if not an application type supported by Liberty
        if (!isSupportedType(artifact.getType())) {
            continue;
        }
        // skip assemblyArtifact if specified as a dependency
        if (assemblyArtifact != null && matches(artifact, assemblyArtifact)) {
            continue;
        }
        if (artifact.getScope().equals("compile")) {
            if (isSupportedType(artifact.getType())) {
                if (looseApplication && isReactorMavenProject(artifact)) {  //Installing the reactor project artifacts
                    MavenProject dependProj = getReactorMavenProject(artifact);
                    installLooseApplication(dependProj);
                } else {
                    installApp(resolveArtifact(artifact));
                }
            } else {
                log.warn(MessageFormat.format(messages.getString("error.application.not.supported"),
                        project.getId()));
            }
        }
    }
}
 
Example 16
Source Project: cxf   Source File: OptionLoader.java    License: Apache License 2.0 5 votes vote down vote up
public static List<WadlOption> loadWsdlOptionsFromDependencies(MavenProject project,
                                                               Option defaultOptions, File outputDir) {
    List<WadlOption> options = new ArrayList<>();
    Set<Artifact> dependencies = project.getDependencyArtifacts();
    for (Artifact artifact : dependencies) {
        WadlOption option = generateWsdlOptionFromArtifact(artifact, outputDir);
        if (option != null) {
            if (defaultOptions != null) {
                option.merge(defaultOptions);
            }
            options.add(option);
        }
    }
    return options;
}
 
Example 17
Source Project: netbeans   Source File: GraphConstructor.java    License: Apache License 2.0 5 votes vote down vote up
private int obtainManagedState(MavenDependencyNode dependencyNode) {        
    if (proj == null) {
        return GraphNode.UNMANAGED;
    }

    DependencyManagement dm = proj.getDependencyManagement();
    if (dm == null) {
        return GraphNode.UNMANAGED;
    }

    @SuppressWarnings("unchecked")
    List<Dependency> deps = dm.getDependencies();
    if (deps == null) {
        return GraphNode.UNMANAGED;
    }

    Artifact artifact = dependencyNode.getArtifact();
    String id = artifact.getArtifactId();
    String groupId = artifact.getGroupId();
    String version = artifact.getVersion();

    for (Dependency dep : deps) {
        if (id.equals(dep.getArtifactId()) && groupId.equals(dep.getGroupId())) {
            if (!version.equals(dep.getVersion())) {
                return GraphNode.OVERRIDES_MANAGED;
            } else {
                return GraphNode.MANAGED;
            }
        }
    }

    return GraphNode.UNMANAGED;
}
 
Example 18
Source Project: pgpverify-maven-plugin   Source File: ScopeSkipperTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructCompileRuntimeScopeFilter() {
    final ScopeSkipper filter = new ScopeSkipper(Artifact.SCOPE_COMPILE_PLUS_RUNTIME);
    assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "system", "jar", "classifier", null)));
    assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "provided", "jar", "classifier", null)));
    assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "compile", "jar", "classifier", null)));
    assertFalse(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "runtime", "jar", "classifier", null)));
    assertTrue(filter.shouldSkipArtifact(new DefaultArtifact("a", "b", "1.0", "test", "jar", "classifier", null)));
}
 
Example 19
Source Project: deadcode4j   Source File: ModuleGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private boolean addKnownArtifact(
        @Nonnull List<Resource> resources,
        @Nonnull Artifact artifact,
        @Nonnull Map<String, Module> knownModules) {
    String dependencyKey = getKeyFor(artifact);
    Module knownModule = knownModules.get(dependencyKey);
    if (knownModule == null) {
        return false;
    }
    resources.add(Resource.of(knownModule));
    logger.debug("  Added project: [{}]", knownModule);
    return true;
}
 
Example 20
Source Project: component-runtime   Source File: ArtifactTransformer.java    License: Apache License 2.0 5 votes vote down vote up
protected boolean isComponent(final Artifact artifact) {
    final File file = artifact.getFile();
    if (file.isDirectory()) {
        return new File(file, "TALEND-INF/dependencies.txt").exists();
    }
    try (final JarFile jar = new JarFile(file)) {
        return jar.getEntry("TALEND-INF/dependencies.txt") != null;
    } catch (final IOException ioe) {
        return false;
    }
}
 
Example 21
Source Project: depgraph-maven-plugin   Source File: DependencyNodeUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void addTypes(DependencyNode dependencyNode, String... types) {
  for (String type : types) {
    Artifact artifact = dependencyNode.getArtifact();
    DependencyNode nodeWithClassifier = new DependencyNode(createArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope(), type, artifact.getClassifier(), artifact.isOptional()));
    dependencyNode.merge(nodeWithClassifier);
  }
}
 
Example 22
Source Project: netbeans   Source File: DependencyNode.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    final Collection<? extends Artifact> artifacts = lkp.lookupAll(Artifact.class);
    if (artifacts.isEmpty()) {
        return;
    }
    Collection<? extends NbMavenProjectImpl> res = lkp.lookupAll(NbMavenProjectImpl.class);
    Set<NbMavenProjectImpl> prjs = new HashSet<NbMavenProjectImpl>(res);
    if (prjs.size() != 1) {
        return;
    }

    final NbMavenProjectImpl project = prjs.iterator().next();
    final List<Artifact> unremoved = new ArrayList<Artifact>();

    final ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
        @Override
        public void performOperation(POMModel model) {
            for (Artifact art : artifacts) {
                org.netbeans.modules.maven.model.pom.Dependency dep =
                        model.getProject().findDependencyById(art.getGroupId(), art.getArtifactId(), null);
                if (dep != null) {
                    model.getProject().removeDependency(dep);
                } else {
                    unremoved.add(art);
                }
            }
        }
    };
    RP.post(new Runnable() {
        @Override
        public void run() {
            FileObject fo = FileUtil.toFileObject(project.getPOMFile());
            Utilities.performPOMModelOperations(fo, Collections.singletonList(operation));
            if (unremoved.size() > 0) {
                StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(DependencyNode.class, "MSG_Located_In_Parent", unremoved.size()), Integer.MAX_VALUE);
            }
        }
    });
}
 
Example 23
Source Project: cxf   Source File: AbstractCodegenMojo.java    License: Apache License 2.0 5 votes vote down vote up
private Artifact resolveDependentWsdl(Artifact artifact) {
    Collection<String> scopes = new ArrayList<>();
    scopes.add(Artifact.SCOPE_RUNTIME);
    Set<Artifact> artifactSet = null;
    try {
        artifactSet = projectDependencyResolver.resolve(project, scopes, mavenSession);
    } catch (AbstractArtifactResolutionException e) {
        getLog().info("Error resolving dependent wsdl artifact.", e);
    }
    return findWsdlArtifact(artifact, artifactSet);
}
 
Example 24
Source Project: extra-enforcer-rules   Source File: JarUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * "Sunny day" test: the method should return true for a jar artifact.
 */
@Test
public void isJarFileShouldReturnTrueForJarFile()
{
    Artifact artifact = newBuilder().withType( "jar" ).build();
    assertTrue( JarUtils.isJarFile( artifact ) );
}
 
Example 25
/**
 * Returns {@code true} if the provided {@code Model} has a dependency on the Dataflow Java SDK
 * with a version other than LATEST or RELEASE.
 */
public boolean hasPinnedDataflowDependency(IProject project) {
  Model model = getModelFromProject(project);
  if (model == null) {
    return false;
  }
  Dependency dependency = getDataflowDependencyFromModel(model);
  if (dependency == null
      || Artifact.LATEST_VERSION.equals(dependency.getVersion())
      || Artifact.RELEASE_VERSION.equals(dependency.getVersion())) {
    return false;
  }
  return true;
}
 
Example 26
Source Project: roboconf-platform   Source File: ResolveMojoTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test( expected = MojoExecutionException.class )
public void testWithInvalidRoboconfDependencies() throws Exception {

	// Prepare the project
	final String projectName = "project--valid";

	File baseDir = this.resources.getBasedir( projectName );
	Assert.assertNotNull( baseDir );
	Assert.assertTrue( baseDir.isDirectory());

	AbstractMojo mojo = findMojo( projectName, "resolve" );
	this.rule.setVariableValueToObject( mojo, "repoSystem", newRepositorySystem());
	this.rule.setVariableValueToObject( mojo, "repositories", new ArrayList<RemoteRepository>( 0 ));

	// Add dependencies
	MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" );
	project.setDependencyArtifacts( new HashSet<Artifact> ());

	Artifact notRbcfArtifact1 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler());
	project.getDependencyArtifacts().add( notRbcfArtifact1 );

	Artifact notRbcfArtifact2 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler());
	notRbcfArtifact2.setFile( new File( "file that does not exist" ));
	project.getDependencyArtifacts().add( notRbcfArtifact2 );

	Artifact notRbcfArtifact3 = new DefaultArtifact( "net.roboconf", "roboconf-core", "0.2", "runtime", "jar", null, new DefaultArtifactHandler());
	File temp = this.folder.newFile( "toto.zip" );
	Assert.assertTrue( temp.exists());

	notRbcfArtifact3.setFile( temp );
	project.getDependencyArtifacts().add( notRbcfArtifact3 );

	// Execute it
	File targetDir = new File( baseDir, MavenPluginConstants.TARGET_MODEL_DIRECTORY + "/" + Constants.PROJECT_DIR_GRAPH );
	Assert.assertFalse( targetDir.isDirectory());
	mojo.execute();
}
 
Example 27
Source Project: wildfly-swarm   Source File: StartMojo.java    License: Apache License 2.0 5 votes vote down vote up
List<Path> dependencies(final Path archiveContent,
                        final boolean scanDependencies) throws MojoFailureException {
    final List<Path> elements = new ArrayList<>();
    final Set<Artifact> artifacts = this.project.getArtifacts();
    boolean hasSwarmDeps = false;
    for (Artifact each : artifacts) {
        if (each.getGroupId().equals(DependencyManager.WILDFLY_SWARM_GROUP_ID)
                && each.getArtifactId().equals(DependencyManager.WILDFLY_SWARM_BOOTSTRAP_ARTIFACT_ID)) {
            hasSwarmDeps = true;
        }
        if (each.getGroupId().equals("org.jboss.logmanager")
                && each.getArtifactId().equals("jboss-logmanager")) {
            continue;
        }
        if (each.getScope().equals("provided")) {
            continue;
        }
        elements.add(each.getFile().toPath());
    }

    elements.add(Paths.get(this.project.getBuild().getOutputDirectory()));

    if (fractionDetectMode != BuildTool.FractionDetectionMode.never) {
        if (fractionDetectMode == BuildTool.FractionDetectionMode.force ||
                !hasSwarmDeps) {
            elements.addAll(findNeededFractions(artifacts, archiveContent, scanDependencies));
        }
    } else if (!hasSwarmDeps) {
        getLog().warn("No WildFly Swarm dependencies found and fraction detection disabled");
    }

    return elements;
}
 
Example 28
Source Project: mvn-golang   Source File: AbstractGoDependencyAwareMojo.java    License: Apache License 2.0 5 votes vote down vote up
@Nonnull
@MustNotContainNull
private List<Tuple<GoMod, File>> listRightPart(@Nonnull @MustNotContainNull final List<Tuple<Artifact, Tuple<GoMod, File>>> list) {
  final List<Tuple<GoMod, File>> parsed = new ArrayList<>();
  for (final Tuple<Artifact, Tuple<GoMod, File>> i : list) {
    parsed.add(i.right());
  }
  return parsed;
}
 
Example 29
Source Project: deadcode4j   Source File: ModuleGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private Predicate<Artifact> artifactsWithCompileScope() {
    return new Predicate<Artifact>() {
        private ScopeArtifactFilter artifactFilter = new ScopeArtifactFilter(Artifact.SCOPE_COMPILE);

        @Override
        public boolean apply(@Nullable Artifact input) {
            return input != null && artifactFilter.include(input);
        }
    };
}
 
Example 30
Source Project: appassembler   Source File: DependencyFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Used by AbstractBooterDaemonGenerator.
 * @param project {@link MavenProject}
 * @param id The id.
 * @param layout {@link ArtifactRepositoryLayout}
 * @param outputFileNameMapping The name mapping.
 * @return the dependency.
 */
public static Dependency create( MavenProject project, String id, ArtifactRepositoryLayout layout,
                                 String outputFileNameMapping )
    throws DaemonGeneratorException
{
    Artifact artifact = (Artifact) project.getArtifactMap().get( id );

    if ( artifact == null )
    {
        throw new DaemonGeneratorException( "The project has to have a dependency on '" + id + "'." );
    }

    return create( artifact, layout, outputFileNameMapping );
}