forked from eclipse-tycho/tycho
/
AbstractTychoPackagingMojo.java
142 lines (118 loc) · 5.17 KB
/
AbstractTychoPackagingMojo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*******************************************************************************
* Copyright (c) 2008, 2022 Sonatype Inc. and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Sonatype Inc. - initial API and implementation
* Christoph Läubrich - Issue #572 - Insert dynamic dependencies into the jar included pom
*******************************************************************************/
package org.eclipse.tycho.packaging;
import java.io.File;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.archiver.FileSet;
import org.codehaus.plexus.archiver.util.DefaultFileSet;
import org.codehaus.plexus.util.AbstractScanner;
import org.eclipse.tycho.BuildProperties;
import org.eclipse.tycho.artifacts.DependencyArtifacts;
import org.eclipse.tycho.core.ArtifactDependencyWalker;
import org.eclipse.tycho.core.TychoProject;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
public abstract class AbstractTychoPackagingMojo extends AbstractMojo {
/**
* The output directory of the jar file
*
* By default this is the Maven "target/" directory.
*/
@Parameter(property = "project.build.directory", required = true)
protected File buildDirectory;
@Parameter(property = "session", readonly = true)
protected MavenSession session;
@Parameter(property = "project", readonly = true)
protected MavenProject project;
@Parameter(defaultValue = "true")
protected boolean useDefaultExcludes;
/**
* Build qualifier. Recommended way to set this parameter is using build-qualifier goal.
*/
@Parameter(property = "buildQualifier")
protected String qualifier;
/**
* If set to <code>true</code> (the default), missing build.properties bin.includes will cause
* build failure. If set to <code>false</code>, missing build.properties bin.includes will be
* reported as warnings but the build will not fail.
*/
@Parameter(defaultValue = "true")
protected boolean strictBinIncludes;
@Component
protected PlexusContainer plexus;
@Component
protected MavenProjectHelper projectHelper;
@Component(role = TychoProject.class)
private Map<String, TychoProject> projectTypes;
@Component
private IncludeValidationHelper includeValidationHelper;
/**
* @return a {@link FileSet} with the given includes and excludes and the configured default
* excludes. An empty list of includes leads to an empty file set.
*/
protected FileSet getFileSet(File basedir, List<String> includes, List<String> excludes) {
DefaultFileSet fileSet = new DefaultFileSet();
fileSet.setDirectory(basedir);
if (includes.isEmpty()) {
// FileSet interprets empty list as "everything", so we need to express "nothing" in a different way
fileSet.setIncludes(new String[] { "" });
} else {
fileSet.setIncludes(includes.toArray(new String[includes.size()]));
}
Set<String> allExcludes = new LinkedHashSet<>();
if (excludes != null) {
allExcludes.addAll(excludes);
}
if (useDefaultExcludes) {
allExcludes.addAll(Arrays.asList(AbstractScanner.DEFAULTEXCLUDES));
// keep ignoring the following files after
// https://github.com/codehaus-plexus/plexus-utils/pull/174
allExcludes.add("**/.gitignore");
allExcludes.add("**/.gitattributes");
}
fileSet.setExcludes(allExcludes.toArray(new String[allExcludes.size()]));
return fileSet;
}
protected ArtifactDependencyWalker getDependencyWalker() {
return getTychoProjectFacet().getDependencyWalker(DefaultReactorProject.adapt(project));
}
protected TychoProject getTychoProjectFacet() {
return getTychoProjectFacet(project.getPackaging());
}
protected TychoProject getTychoProjectFacet(String packaging) {
TychoProject facet = projectTypes.get(packaging);
if (facet == null) {
throw new IllegalStateException("Unknown or unsupported packaging type " + packaging);
}
return facet;
}
protected DependencyArtifacts getDependencyArtifacts() {
return getTychoProjectFacet().getDependencyArtifacts(DefaultReactorProject.adapt(project));
}
protected void checkBinIncludesExist(BuildProperties buildProperties, String... ignoredIncludes)
throws MojoExecutionException {
includeValidationHelper.checkBinIncludesExist(project, buildProperties, strictBinIncludes, ignoredIncludes);
}
}