Search in sources :

Example 16 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.

the class RemoteResourcesMojoTest method testSimpleBundlesWithType.

public void testSimpleBundlesWithType() throws Exception {
    final MavenProjectResourcesStub project = createTestProject("default-simplebundles");
    final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test:test:1.0:war" });
    setupDefaultProject(project);
    ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
    String path = repo.pathOf(new DefaultArtifact("test", "test", VersionRange.createFromVersion("1.0"), null, "war", "", new DefaultArtifactHandler()));
    File file = new File(repo.getBasedir() + "/" + path + ".war");
    file.getParentFile().mkdirs();
    buildResourceBundle("default-simplebundles-create", null, new String[] { "SIMPLE.txt" }, file);
    mojo.execute();
    file = (File) getVariableValueFromObject(mojo, "outputDirectory");
    file = new File(file, "SIMPLE.txt");
    assertTrue(file.exists());
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 17 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.

the class RemoteResourcesMojoTest method testFilteredBundlesWithProjectProperties.

public void testFilteredBundlesWithProjectProperties() throws Exception {
    final MavenProjectResourcesStub project = createTestProject("default-filterbundles-two");
    final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test-filtered-bundles:test-filtered-bundles:2" });
    mojo.includeProjectProperties = true;
    setupDefaultProject(project);
    project.addProperty("testingPropertyOne", "maven");
    project.addProperty("testingPropertyTwo", "rules");
    ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
    String path = repo.pathOf(new DefaultArtifact("test-filtered-bundles", "test-filtered-bundles", VersionRange.createFromVersion("2"), null, "jar", "", new DefaultArtifactHandler()));
    File file = new File(repo.getBasedir() + "/" + path + ".jar");
    file.getParentFile().mkdirs();
    buildResourceBundle("default-filterbundles-two-create", null, new String[] { "PROPERTIES.txt.vm" }, file);
    mojo.execute();
    // executing a second time (example: forked lifecycle) should still work
    mojo.execute();
    file = (File) getVariableValueFromObject(mojo, "outputDirectory");
    file = new File(file, "PROPERTIES.txt");
    assertTrue(file.exists());
    String data = FileUtils.fileRead(file);
    assertTrue(data.contains("maven"));
    assertTrue(data.contains("rules"));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 18 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.

the class ShadeMojoTest method testShadeWithFilter.

/**
 * Tests if a Filter is installed correctly, also if createSourcesJar is set to true.
 *
 * @throws Exception
 */
public void testShadeWithFilter() throws Exception {
    ShadeMojo mojo = new ShadeMojo();
    // set createSourcesJar = true
    Field createSourcesJar = ShadeMojo.class.getDeclaredField("createSourcesJar");
    createSourcesJar.setAccessible(true);
    createSourcesJar.set(mojo, Boolean.TRUE);
    // configure artifactResolver (mocked) for mojo
    ArtifactResolver mockArtifactResolver = new ArtifactResolver() {

        @Override
        public ArtifactResult resolveArtifact(ProjectBuildingRequest req, final Artifact art) throws ArtifactResolverException {
            return new ArtifactResult() {

                @Override
                public Artifact getArtifact() {
                    art.setResolved(true);
                    String fileName = art.getArtifactId() + "-" + art.getVersion() + (art.getClassifier() != null ? "-" + art.getClassifier() : "") + ".jar";
                    art.setFile(new File(fileName));
                    return art;
                }
            };
        }

        @Override
        public ArtifactResult resolveArtifact(ProjectBuildingRequest req, final ArtifactCoordinate coordinate) throws ArtifactResolverException {
            return new ArtifactResult() {

                @Override
                public Artifact getArtifact() {
                    Artifact art = mock(Artifact.class);
                    when(art.getGroupId()).thenReturn(coordinate.getGroupId());
                    when(art.getArtifactId()).thenReturn(coordinate.getArtifactId());
                    when(art.getType()).thenReturn(coordinate.getExtension());
                    when(art.getClassifier()).thenReturn(coordinate.getClassifier());
                    when(art.isResolved()).thenReturn(true);
                    String fileName = coordinate.getArtifactId() + "-" + coordinate.getVersion() + (coordinate.getClassifier() != null ? "-" + coordinate.getClassifier() : "") + ".jar";
                    when(art.getFile()).thenReturn(new File(fileName));
                    return art;
                }
            };
        }
    };
    Field artifactResolverField = ShadeMojo.class.getDeclaredField("artifactResolver");
    artifactResolverField.setAccessible(true);
    artifactResolverField.set(mojo, mockArtifactResolver);
    // create and configure MavenProject
    MavenProject project = new MavenProject();
    ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE);
    Artifact artifact = new DefaultArtifact("org.apache.myfaces.core", "myfaces-impl", VersionRange.createFromVersion("2.0.1-SNAPSHOT"), "compile", "jar", null, artifactHandler);
    // setFile and setResolved
    artifact = mockArtifactResolver.resolveArtifact(null, artifact).getArtifact();
    project.setArtifact(artifact);
    Field projectField = ShadeMojo.class.getDeclaredField("project");
    projectField.setAccessible(true);
    projectField.set(mojo, project);
    // create and configure the ArchiveFilter
    ArchiveFilter archiveFilter = new ArchiveFilter();
    Field archiveFilterArtifact = ArchiveFilter.class.getDeclaredField("artifact");
    archiveFilterArtifact.setAccessible(true);
    archiveFilterArtifact.set(archiveFilter, "org.apache.myfaces.core:myfaces-impl");
    // add ArchiveFilter to mojo
    Field filtersField = ShadeMojo.class.getDeclaredField("filters");
    filtersField.setAccessible(true);
    filtersField.set(mojo, new ArchiveFilter[] { archiveFilter });
    Field sessionField = ShadeMojo.class.getDeclaredField("session");
    sessionField.setAccessible(true);
    sessionField.set(mojo, mock(MavenSession.class));
    // invoke getFilters()
    Method getFilters = ShadeMojo.class.getDeclaredMethod("getFilters", new Class[0]);
    getFilters.setAccessible(true);
    List<Filter> filters = (List<Filter>) getFilters.invoke(mojo);
    // assertions - there must be one filter
    assertEquals(1, filters.size());
    // the filter must be able to filter the binary and the sources jar
    Filter filter = filters.get(0);
    // binary jar
    assertTrue(filter.canFilter(new File("myfaces-impl-2.0.1-SNAPSHOT.jar")));
    // sources jar
    assertTrue(filter.canFilter(new File("myfaces-impl-2.0.1-SNAPSHOT-sources.jar")));
}
Also used : ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) Method(java.lang.reflect.Method) ArtifactResolver(org.apache.maven.shared.artifact.resolve.ArtifactResolver) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) Field(java.lang.reflect.Field) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MavenSession(org.apache.maven.execution.MavenSession) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) Filter(org.apache.maven.plugins.shade.filter.Filter) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 19 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.

the class AbstractAntTestMavenProjectStub method getTestArtifacts.

/**
 * @see org.apache.maven.project.MavenProject#getTestArtifacts()
 */
public List getTestArtifacts() {
    Artifact junit = new DefaultArtifact("junit", "junit", VersionRange.createFromVersion("3.8.2"), Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler("jar"), false);
    junit.setFile(new File("junit/junit/3.8.2/junit-3.8.2.jar"));
    return Collections.singletonList(junit);
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 20 with DefaultArtifact

use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.

the class AbstractAntTestMavenProjectStub method getCompileArtifacts.

/**
 * @see org.apache.maven.project.MavenProject#getCompileArtifacts()
 */
public List getCompileArtifacts() {
    Artifact junit = new DefaultArtifact("junit", "junit", VersionRange.createFromVersion("3.8.2"), Artifact.SCOPE_TEST, "jar", null, new DefaultArtifactHandler("jar"), false);
    junit.setFile(new File("junit/junit/3.8.2/junit-3.8.2.jar"));
    return Collections.singletonList(junit);
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)51 Artifact (org.apache.maven.artifact.Artifact)35 File (java.io.File)26 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)26 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)22 VersionRange (org.apache.maven.artifact.versioning.VersionRange)17 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)10 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)10 MavenProject (org.apache.maven.project.MavenProject)9 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4 InputStream (java.io.InputStream)3 List (java.util.List)3 Map (java.util.Map)3 DefaultArtifactRepository (org.apache.maven.artifact.repository.DefaultArtifactRepository)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2