use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class CompilerMojoTestCase method getTestCompilerMojo.
private TestCompilerMojo getTestCompilerMojo(CompilerMojo compilerMojo, String pomXml) throws Exception {
File testPom = new File(getBasedir(), pomXml);
TestCompilerMojo mojo = (TestCompilerMojo) lookupMojo("testCompile", testPom);
setVariableValueToObject(mojo, "log", new DebugEnabledLog());
File buildDir = (File) getVariableValueFromObject(compilerMojo, "buildDirectory");
File testClassesDir = new File(buildDir, "test-classes");
setVariableValueToObject(mojo, "outputDirectory", testClassesDir);
List<String> testClasspathList = new ArrayList<String>();
Artifact junitArtifact = mock(Artifact.class);
ArtifactHandler handler = mock(ArtifactHandler.class);
when(handler.isAddedToClasspath()).thenReturn(true);
when(junitArtifact.getArtifactHandler()).thenReturn(handler);
File artifactFile;
String localRepository = System.getProperty("localRepository");
if (localRepository != null) {
artifactFile = new File(localRepository, "junit/junit/3.8.1/junit-3.8.1.jar");
} else {
// for IDE
String junitURI = org.junit.Test.class.getResource("Test.class").toURI().toString();
junitURI = junitURI.substring("jar:".length(), junitURI.indexOf('!'));
artifactFile = new File(URI.create(junitURI));
}
when(junitArtifact.getFile()).thenReturn(artifactFile);
testClasspathList.add(artifactFile.getAbsolutePath());
testClasspathList.add(compilerMojo.getOutputDirectory().getPath());
String testSourceRoot = testPom.getParent() + "/src/test/java";
setVariableValueToObject(mojo, "compileSourceRoots", Collections.singletonList(testSourceRoot));
MavenProject project = getMockMavenProject();
project.setArtifacts(Collections.singleton(junitArtifact));
project.getBuild().setOutputDirectory(new File(buildDir, "classes").getAbsolutePath());
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "compilePath", Collections.EMPTY_LIST);
setVariableValueToObject(mojo, "testPath", testClasspathList);
setVariableValueToObject(mojo, "session", getMockMavenSession());
setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
setVariableValueToObject(mojo, "source", source);
setVariableValueToObject(mojo, "target", target);
return mojo;
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class AbstractEarTestBase method createArtifacts.
protected Set<Artifact> createArtifacts(String[] artifactsId, String[] types, String[] groupsId, String[] classifiers) {
Set<Artifact> result = new TreeSet<Artifact>();
if (artifactsId == null || artifactsId.length == 0) {
return result;
}
for (int i = 0; i < artifactsId.length; i++) {
String artifactId = artifactsId[i];
String type = getData(types, i, DEFAULT_TYPE);
String groupId = getData(groupsId, i, DEFAULT_GROUPID);
String classifier = getData(classifiers, i, null);
result.add(new ArtifactTestStub(groupId, artifactId, type, classifier));
}
return result;
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class ModuleIdentifierValidatorTest method createMockEarModule.
private EarModule createMockEarModule(String groupId, String artifactId, String classifier, String version) {
EarModule earModule = mock(EarModule.class);
Artifact artifact = mock(Artifact.class);
when(earModule.getArtifact()).thenReturn(artifact);
when(earModule.getArtifact().getGroupId()).thenReturn(groupId);
when(earModule.getArtifact().getArtifactId()).thenReturn(artifactId);
when(earModule.getArtifact().getClassifier()).thenReturn(classifier);
when(earModule.getArtifact().getVersion()).thenReturn(version);
when(earModule.getArtifact().getId()).thenReturn(groupId + ":" + artifactId + ":" + classifier + ":" + version);
return earModule;
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class TestAbstractFileNameMapping method test.
@Test
public void test() {
ArtifactHandler handler = mock(ArtifactHandler.class);
when(handler.getExtension()).thenReturn("jar");
Artifact artifact = mock(Artifact.class);
when(artifact.getArtifactHandler()).thenReturn(handler);
when(artifact.getArtifactId()).thenReturn("mear149");
when(artifact.getVersion()).thenReturn("1.0-SNAPSHOT");
when(artifact.getBaseVersion()).thenReturn("1.0-20130423.042904");
// default behavior: use -SNAPSHOT
assertEquals("mear149-1.0-SNAPSHOT.jar", abstractFileNameMapping.generateFileName(artifact, true));
abstractFileNameMapping.setUseBaseVersion(true);
assertEquals("mear149-1.0-20130423.042904.jar", abstractFileNameMapping.generateFileName(artifact, true));
abstractFileNameMapping.setUseBaseVersion(false);
assertEquals("mear149-1.0-SNAPSHOT.jar", abstractFileNameMapping.generateFileName(artifact, true));
}
use of org.apache.maven.artifact.Artifact in project maven-plugins by apache.
the class GpgSignAttachedMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
// We're skipping the signing stuff
return;
}
if (excludes == null || excludes.length == 0) {
excludes = DEFAULT_EXCLUDES;
}
String[] newExcludes = new String[excludes.length];
for (int i = 0; i < excludes.length; i++) {
String pattern;
pattern = excludes[i].trim().replace('/', File.separatorChar).replace('\\', File.separatorChar);
if (pattern.endsWith(File.separator)) {
pattern += "**";
}
newExcludes[i] = pattern;
}
excludes = newExcludes;
AbstractGpgSigner signer = newSigner(project);
// ----------------------------------------------------------------------------
// What we need to generateSignatureForArtifact here
// ----------------------------------------------------------------------------
signer.setOutputDirectory(ascDirectory);
signer.setBuildDirectory(new File(project.getBuild().getDirectory()));
signer.setBaseDirectory(project.getBasedir());
List signingBundles = new ArrayList();
if (!"pom".equals(project.getPackaging())) {
// ----------------------------------------------------------------------------
// Project artifact
// ----------------------------------------------------------------------------
Artifact artifact = project.getArtifact();
File file = artifact.getFile();
if (file != null && file.isFile()) {
getLog().debug("Generating signature for " + file);
File projectArtifactSignature = signer.generateSignatureForArtifact(file);
if (projectArtifactSignature != null) {
signingBundles.add(new SigningBundle(artifact.getArtifactHandler().getExtension(), projectArtifactSignature));
}
} else if (project.getAttachedArtifacts().isEmpty()) {
throw new MojoFailureException("The project artifact has not been assembled yet. " + "Please do not invoke this goal before the lifecycle phase \"package\".");
} else {
getLog().debug("Main artifact not assembled, skipping signature generation");
}
}
// ----------------------------------------------------------------------------
// POM
// ----------------------------------------------------------------------------
File pomToSign = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".pom");
try {
FileUtils.copyFile(project.getFile(), pomToSign);
} catch (IOException e) {
throw new MojoExecutionException("Error copying POM for signing.", e);
}
getLog().debug("Generating signature for " + pomToSign);
File pomSignature = signer.generateSignatureForArtifact(pomToSign);
if (pomSignature != null) {
signingBundles.add(new SigningBundle("pom", pomSignature));
}
for (Object o : project.getAttachedArtifacts()) {
Artifact artifact = (Artifact) o;
File file = artifact.getFile();
getLog().debug("Generating signature for " + file);
File signature = signer.generateSignatureForArtifact(file);
if (signature != null) {
signingBundles.add(new SigningBundle(artifact.getArtifactHandler().getExtension(), artifact.getClassifier(), signature));
}
}
for (Object signingBundle : signingBundles) {
SigningBundle bundle = (SigningBundle) signingBundle;
projectHelper.attachArtifact(project, bundle.getExtension() + GpgSigner.SIGNATURE_EXTENSION, bundle.getClassifier(), bundle.getSignature());
}
}
Aggregations