maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathalie Keymeulen <nathalie.keymeu...@agfa.com>
Subject Harnes 3.3.0 - Test fails to resolve artifact
Date Wed, 02 Dec 2015 11:15:43 GMT
Hi,

I would like to use Harness for testing our maven plugin (maven 3)

We are downloading an artifact to our local repository.
When running the plugin the download is correctly done but when I try to 
test this behavior (download) with harness I get the following error when 
running SetupMojoTest : 

org.apache.maven.plugin.MojoExecutionException: Could not resolve 
artifact: org.apache.commons:commons-lang3:jar:3.4
        at SetupMojo.resolveArtifact(SetupMojo.java:62)
        at com.oas.maven.mojo.SetupMojo.execute(SetupMojo.java:42)
        at 
com.oas.maven.mojo.SetupMojoTest.testSomething(SetupMojoTest.java:36)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at junit.framework.TestSuite.runTest(TestSuite.java:208)
        at junit.framework.TestSuite.run(TestSuite.java:203)
        at 
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.maven.artifact.resolver.ArtifactResolutionException: 
Could not transfer artifact org.apache.commons:commons-lang3:jar:3.4 
from/to central (http://repo.maven.apache.org/maven2): No connector 
factories available
  org.apache.commons:commons-lang3:jar:3.4

from the specified remote repositories:
  central (http://repo.maven.apache.org/maven2, releases=true, 
snapshots=true)

        at 
org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:222)
        at 
org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:401)
        at 
org.apache.maven.repository.legacy.LegacyRepositorySystem.resolve(LegacyRepositorySystem.java:353)
        at 
com.agfa.occ.oas.maven.mojo.SetupMojo.resolveArtifact(SetupMojo.java:60)
        ... 20 more
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: 
Could not transfer artifact org.apache.commons:commons-lang3:jar:3.4 
from/to central (http://repo.maven.apache.org/maven2): No connector 
factories available
        at 
org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
        at 
org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
        at 
org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223)
        at 
org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:294)
        at 
org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:212)
        ... 23 more
Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could 
not transfer artifact org.apache.commons:commons-lang3:jar:3.4 from/to 
central (http://repo.maven.apache.org/maven2): No connector factories 
available
        at 
org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:531)
        at 
org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421)
        ... 27 more
Caused by: org.eclipse.aether.transfer.NoRepositoryConnectorException: No 
connector factories available
        at 
org.eclipse.aether.internal.impl.DefaultRepositoryConnectorProvider.newRepositoryConnector(DefaultRepositoryConnectorProvider.java:174)
        at 
org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:516)
        ... 28 more

------------------------------------------------------------------------------------
maven-plugin : pom.xml

        <dependencies>
 
                <dependency>
                        <groupId>org.apache.maven.plugin-tools</groupId>
                        <artifactId>maven-plugin-annotations</artifactId>
                        <version>3.3</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>org.apache.maven</groupId>
                        <artifactId>maven-core</artifactId>
                        <version>${version.maven}</version>
                        <scope>provided</scope>
                </dependency> 
            <dependency>
                <groupId>org.apache.maven</groupId>
                <artifactId>maven-core</artifactId>
                <version>${version.maven}</version>
                        <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.maven</groupId>
                <artifactId>maven-plugin-api</artifactId>
                <version>${version.maven}</version>
                        <scope>provided</scope> 
            </dependency>
            <dependency>
              <groupId>org.apache.maven</groupId>
              <artifactId>maven-model</artifactId>
              <version>${version.maven}</version>
                  <scope>provided</scope> 
            </dependency>
            <dependency>
                        <groupId>org.apache.maven</groupId>
                        <artifactId>maven-artifact</artifactId>
                        <version>${version.maven}</version>
            </dependency>
            <dependency>
              <groupId>org.apache.maven</groupId>
              <artifactId>maven-compat</artifactId>
              <version>${version.maven}</version>
                  <scope>test</scope> 
            </dependency>
            <dependency>
              <groupId>org.apache.maven</groupId>
              <artifactId>maven-aether-provider</artifactId>
              <version>${version.maven}</version>
                  <scope>test</scope> 
            </dependency>
            <dependency>
                <groupId>org.apache.maven.plugin-testing</groupId>
                <artifactId>maven-plugin-testing-harness</artifactId>
                <version>3.3.0</version>
                <scope>test</scope> 
            </dependency>
        </dependencies>
        <properties>
                <version.maven>3.3.3</version.maven>
        </properties>

-----------------------------------------------------------------------------------

@Mojo(name = "setup", threadSafe = true, defaultPhase = LifecyclePhase.
PACKAGE, requiresDependencyResolution = ResolutionScope.TEST)
public class SetupMojo extends AbstractMojo { 
 
        @Parameter(defaultValue = "${project}", readonly = true)
        protected MavenProject project;
 
        @Component
        private RepositorySystem repositorySystem;
 
        @Component
        protected ProjectDependenciesResolver projectDependenciesResolver;
 
        @Parameter(defaultValue = "${localRepository}", readonly=true, 
required=true)
        protected ArtifactRepository localRepository;
 
        @Override
        public void execute() throws MojoExecutionException, 
MojoFailureException{
            final Artifact overlayArtifact = buildArtifact(
"org.apache.commons", "commons-lang3", "3.4"); 
                resolveArtifact(overlayArtifact); 
        }

        private Artifact buildArtifact(final String groupId, final String 
artifactId, final String version) {
                final Dependency dependency = new Dependency();
        dependency.setGroupId(groupId);
        dependency.setArtifactId(artifactId);
        dependency.setVersion(version);
 
        final Artifact overlayArtifact = repositorySystem
.createDependencyArtifact(dependency);
                return overlayArtifact;
        }

        public File resolveArtifact(final Artifact artifact) throws 
MojoExecutionException {
            final ArtifactResolutionRequest request = new 
ArtifactResolutionRequest()
                .setArtifact(artifact)
                .setRemoteRepositories(project
.getRemoteArtifactRepositories())
                .setLocalRepository(localRepository);
            final ArtifactResolutionResult resolutionResult = 
repositorySystem.resolve(request);
            if(resolutionResult.hasExceptions()){
                throw new MojoExecutionException("Could not resolve 
artifact: " + artifact, resolutionResult.getExceptions().get(0));
            }
            getLog().info(artifact + " : " + artifact
.getFile().getAbsolutePath());
            return artifact.getFile();
        }
}

----------------------------------------------------------------------------------------

public class SetupMojoTest extends AbstractMojoTestCase {
 
        /** {@inheritDoc} */
        @Override
        protected void setUp() throws Exception {
                // required
                super.setUp();

        }

        /** {@inheritDoc} */
        @Override
        protected void tearDown() throws Exception {
                // required
                super.tearDown();

        }

        /**
         * @throws Exception
         *             if any
         */
        public void testSomething() throws Exception {
                final File pom = getTestFile(
"src/test/resources/unit/setup/pom.xml");
                assertNotNull(pom);
                assertTrue(pom.exists());

                final SetupMojo setupMojo = (SetupMojo) lookupMojo("setup"
, pom);
                assertNotNull(setupMojo);
                setupMojo.execute();

        }
}
-----------------------------------------------------------------------------
public class MyProjectStub extends MavenProjectStub {
        /**
         * Default constructor
         */
        public MyProjectStub() {
                final MavenXpp3Reader pomReader = new MavenXpp3Reader();
                Model model;
                try {
                        model = pomReader.read(ReaderFactory.newXmlReader(
new File(
                                        getBasedir(), 
"/unit/setup/pom.xml")));
                        setModel(model);
                } catch (final Exception e) {
                        throw new RuntimeException(e);
                }

                setGroupId(model.getGroupId());
                setArtifactId(model.getArtifactId());
                setVersion(model.getVersion());
                setName(model.getName());
                setUrl(model.getUrl());
                setPackaging(model.getPackaging());

                final Build build = new Build();
                build.setFinalName(model.getArtifactId());
                build.setDirectory(getBasedir() + "/target");
                build.setSourceDirectory(getBasedir() + "/src/main/java");
                build.setOutputDirectory(getBasedir() + "/target/classes"
);
                build.setTestSourceDirectory(getBasedir() + 
"/src/test/java");
                build.setTestOutputDirectory(getBasedir() + 
"/target/test-classes");
                setBuild(build);

                final List<String> compileSourceRoots = new 
ArrayList<String>();
                compileSourceRoots.add(getBasedir() + "/src/main/java");
                setCompileSourceRoots(compileSourceRoots);

                final List<String> testCompileSourceRoots = new 
ArrayList<String>();
                testCompileSourceRoots.add(getBasedir() + "/src/test/java"
);
                setTestCompileSourceRoots(testCompileSourceRoots);
        }

 
        /** {@inheritDoc} */
        @Override
        public List<ArtifactRepository> getRemoteArtifactRepositories() {
                final ArtifactRepository repository = new 
DefaultArtifactRepository("central", "http://repo.maven.apache.org/maven2"
,new DefaultRepositoryLayout());
                return Collections.singletonList(repository);
        }
 
        /** {@inheritDoc} */
        @Override
        public File getBasedir() {
                return new File(super.getBasedir() + 
"/src/test/resources/");
        }
}
------------------------------------------------------
src/test/resources/unit/setup/pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.occ.maven</groupId>
        <artifactId>test-setup</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <packaging>pom</packaging>
        <name>Test SetupMojo</name>
 
        <build>
                <plugins>
                        <plugin>
                                <groupId>com.occ.maven</groupId>
                                <artifactId>oas</artifactId> 
                                <version>1.0.0-SNAPSHOT</version>
                                <configuration>
                                        <project implementation=
"com.occ.oas.maven.mojo.stubs.MyProjectStub"/> 
                                        <localRepository>
${localRepository}</localRepository> 
                                </configuration> 
                        </plugin>
                </plugins>
        </build>
 
</project>


Kind Regards,

Nathalie Keymeulen | Agfa HealthCare
Software Engineer | HE/Orbis Connectivity Core Team Ghent | IT BD, 
Enterprise BU
T  +32 3444 7644 | F  +32 3 444 8401 | M  +32 494 56 02 80

Moutstraat 100, B-9000 Ghent, Belgium
http://www.agfahealthcare.com
http://blog.agfahealthcare.com
Click on link to read important disclaimer: 
http://www.agfahealthcare.com/maildisclaimer 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message