| 1 |
package org.debian.maven.packager.util; |
| 2 |
|
| 3 |
import java.util.Set; |
| 4 |
import java.util.TreeSet; |
| 5 |
|
| 6 |
import org.debian.maven.packager.interaction.YesNoQuestion; |
| 7 |
import org.debian.maven.repo.Dependency; |
| 8 |
|
| 9 |
public class IgnoreDependencyQuestions { |
| 10 |
|
| 11 |
private Set<Dependency> notIgnoredDependencies = new TreeSet<Dependency>(); |
| 12 |
private final boolean interactive; |
| 13 |
|
| 14 |
/** Dependencies to ignore, because they have been integrated to recent versions of the JRE */ |
| 15 |
private static final String[][] DEPENDENCIES_TO_IGNORE = { |
| 16 |
// JAXB (added to Java 6) |
| 17 |
{"jaxme", "jaxme-api"}, |
| 18 |
{"jaxme", "jaxmeapi"}, |
| 19 |
{"org.apache.ws.jaxme", "jaxmeapi"}, |
| 20 |
{"org.apache.geronimo.specs", "geronimo-jaxb_2.1_spec"}, |
| 21 |
{"org.apache.geronimo.specs", "geronimo-jaxb_2.2_spec"}, |
| 22 |
{"jaxb", "jsr173_api"}, |
| 23 |
// JMX (added to Java 5) |
| 24 |
{"mx4j", "mx4j"}, |
| 25 |
{"mx4j", "mx4j-jmx"}, |
| 26 |
// Java XML Streaming API (added to Java 6) |
| 27 |
{"stax", "stax"}, |
| 28 |
{"stax", "stax-api"}, |
| 29 |
{"javax.xml.stream", "stax-api"}, |
| 30 |
{"org.apache.geronimo.specs", "geronimo-stax-api_1.2_spec"}, |
| 31 |
}; |
| 32 |
|
| 33 |
/** Plugins not useful for the build or whose use is against the Debian policy */ |
| 34 |
private static final String[][] PLUGINS_TO_IGNORE = { |
| 35 |
{"org.apache.maven.plugins", "maven-archetype-plugin"}, |
| 36 |
{"org.apache.maven.plugins", "changelog-maven-plugin"}, |
| 37 |
{"org.apache.maven.plugins", "maven-deploy-plugin"}, |
| 38 |
{"org.apache.maven.plugins", "maven-docck-plugin"}, |
| 39 |
{"org.apache.maven.plugins", "maven-doap-plugin"}, |
| 40 |
{"org.apache.maven.plugins", "maven-release-plugin"}, |
| 41 |
{"org.apache.maven.plugins", "maven-repository-plugin"}, |
| 42 |
{"org.apache.maven.plugins", "maven-scm-plugin"}, |
| 43 |
{"org.apache.maven.plugins", "maven-scm-publish-plugin"}, |
| 44 |
{"org.apache.maven.plugins", "maven-stage-plugin"}, |
| 45 |
{"org.apache.maven.plugins", "maven-eclipse-plugin"}, |
| 46 |
{"org.apache.maven.plugins", "maven-idea-plugin"}, |
| 47 |
{"org.apache.maven.plugins", "maven-source-plugin"}, |
| 48 |
{"org.codehaus.mojo", "animal-sniffer-maven-plugin"}, |
| 49 |
{"org.codehaus.mojo", "changelog-maven-plugin"}, |
| 50 |
{"org.codehaus.mojo", "netbeans-freeform-maven-plugin"}, |
| 51 |
{"org.codehaus.mojo", "nbm-maven-plugin"}, |
| 52 |
{"org.codehaus.mojo", "ideauidesigner-maven-plugin"}, |
| 53 |
{"org.codehaus.mojo", "scmchangelog-maven-plugin"}, |
| 54 |
{"com.coveo", "fmt-maven-plugin"}, |
| 55 |
{"com.diffplug.spotless", "spotless-maven-plugin"}, |
| 56 |
{"com.github.github", "site-maven-plugin"}, |
| 57 |
{"com.googlecode.maven-gcu-plugin", "maven-gcu-plugin"}, |
| 58 |
{"org.sonatype.plugins", "nexus-staging-maven-plugin"}, |
| 59 |
{"org.sonatype.ossindex.maven", "ossindex-maven-plugin"}, |
| 60 |
{"org.eluder.coveralls", "coveralls-maven-plugin"}, |
| 61 |
}; |
| 62 |
|
| 63 |
private static final String[][] PLUGINS_THAT_CAN_BE_IGNORED = { |
| 64 |
{"com.github.spotbugs", "spotbugs-maven-plugin"}, |
| 65 |
{"org.apache.maven.plugins", "maven-ant-plugin"}, |
| 66 |
{"org.apache.maven.plugins", "maven-assembly-plugin"}, |
| 67 |
{"org.apache.maven.plugins", "maven-enforcer-plugin"}, |
| 68 |
{"org.apache.maven.plugins", "maven-gpg-plugin"}, |
| 69 |
{"org.apache.rat", "apache-rat-plugin"}, |
| 70 |
{"org.codehaus.mojo", "rat-maven-plugin"}, |
| 71 |
{"org.codehaus.mojo", "buildnumber-maven-plugin"}, |
| 72 |
{"org.apache.maven.plugins", "maven-verifier-plugin"}, |
| 73 |
{"org.codehaus.mojo", "findbugs-maven-plugin"}, |
| 74 |
{"org.codehaus.mojo", "fitnesse-maven-plugin"}, |
| 75 |
{"org.codehaus.mojo", "ianal-maven-plugin"}, |
| 76 |
{"org.codehaus.mojo", "selenium-maven-plugin"}, |
| 77 |
{"org.codehaus.mojo", "dbunit-maven-plugin"}, |
| 78 |
{"org.codehaus.mojo", "failsafe-maven-plugin"}, |
| 79 |
{"org.codehaus.mojo", "shitty-maven-plugin"}, |
| 80 |
{"org.glassfish.copyright", "glassfish-copyright-maven-plugin"}, |
| 81 |
{"com.mycila.maven-license-plugin", "maven-license-plugin"}, |
| 82 |
{"com.google.code.maven-license-plugin", "maven-license-plugin"}, |
| 83 |
}; |
| 84 |
|
| 85 |
private static final String[][] DOC_PLUGINS = { |
| 86 |
{"org.apache.maven.plugins", "maven-changelog-plugin"}, |
| 87 |
{"org.apache.maven.plugins", "maven-changes-plugin"}, |
| 88 |
{"org.apache.maven.plugins", "maven-checkstyle-plugin"}, |
| 89 |
{"org.apache.maven.plugins", "maven-clover-plugin"}, |
| 90 |
{"org.apache.maven.plugins", "maven-javadoc-plugin"}, |
| 91 |
{"org.apache.maven.plugins", "maven-jxr-plugin"}, |
| 92 |
{"org.apache.maven.plugins", "maven-pmd-plugin"}, |
| 93 |
{"org.apache.maven.plugins", "maven-project-info-reports-plugin"}, |
| 94 |
{"org.apache.maven.plugins", "maven-surefire-report-plugin"}, |
| 95 |
{"org.apache.maven.plugins", "maven-pdf-plugin"}, |
| 96 |
{"org.apache.maven.plugins", "maven-site-plugin"}, |
| 97 |
{"org.codehaus.mojo", "changes-maven-plugin"}, |
| 98 |
{"org.codehaus.mojo", "clirr-maven-plugin"}, |
| 99 |
{"org.codehaus.mojo", "cobertura-maven-plugin"}, |
| 100 |
{"org.codehaus.mojo", "taglist-maven-plugin"}, |
| 101 |
{"org.codehaus.mojo", "dita-maven-plugin"}, |
| 102 |
{"org.codehaus.mojo", "docbook-maven-plugin"}, |
| 103 |
{"org.codehaus.mojo", "javancss-maven-plugin"}, |
| 104 |
{"org.codehaus.mojo", "jdepend-maven-plugin"}, |
| 105 |
{"org.codehaus.mojo", "jxr-maven-plugin"}, |
| 106 |
{"org.codehaus.mojo", "l10n-maven-plugin"}, |
| 107 |
{"org.codehaus.mojo", "dashboard-maven-plugin"}, |
| 108 |
{"org.codehaus.mojo", "emma-maven-plugin"}, |
| 109 |
{"org.codehaus.mojo", "sonar-maven-plugin"}, |
| 110 |
{"org.codehaus.mojo", "surefire-report-maven-plugin"}, |
| 111 |
{"org.jboss.maven.plugins", "maven-jdocbook-plugin"}, |
| 112 |
{"org.jacoco", "jacoco-maven-plugin"}, |
| 113 |
}; |
| 114 |
|
| 115 |
private static final String[][] TEST_PLUGINS = { |
| 116 |
{"org.apache.maven.plugins", "maven-failsafe-plugin"}, |
| 117 |
{"org.apache.maven.plugins", "maven-surefire-plugin"}, |
| 118 |
{"org.apache.maven.plugins", "maven-verifier-plugin"}, |
| 119 |
{"org.codehaus.mojo", "findbugs-maven-plugin"}, |
| 120 |
{"org.codehaus.mojo", "fitnesse-maven-plugin"}, |
| 121 |
{"org.codehaus.mojo", "selenium-maven-plugin"}, |
| 122 |
{"org.codehaus.mojo", "dbunit-maven-plugin"}, |
| 123 |
{"org.codehaus.mojo", "failsafe-maven-plugin"}, |
| 124 |
{"org.codehaus.mojo", "shitty-maven-plugin"}, |
| 125 |
}; |
| 126 |
|
| 127 |
private static final String[][] EXTENSIONS_TO_IGNORE = { |
| 128 |
{"org.apache.maven.wagon", "wagon-ssh"}, |
| 129 |
{"org.apache.maven.wagon", "wagon-ssh-external"}, |
| 130 |
{"org.apache.maven.wagon", "wagon-ftp"}, |
| 131 |
{"org.apache.maven.wagon", "wagon-http"}, |
| 132 |
{"org.apache.maven.wagon", "wagon-http-lightweight"}, |
| 133 |
{"org.apache.maven.wagon", "wagon-scm"}, |
| 134 |
{"org.apache.maven.wagon", "wagon-webdav"}, |
| 135 |
{"org.apache.maven.wagon", "wagon-webdav-jackrabbit"}, |
| 136 |
{"org.jvnet.wagon-svn", "wagon-svn"}, |
| 137 |
{"org.kathrynhuxtable.maven.wagon", "wagon-gitsite"}, |
| 138 |
{"com.github.stephenc.wagon", "wagon-gitsite"}, |
| 139 |
{"com.google.code.maven-svn-wagon", "maven-svn-wagon"}, |
| 140 |
}; |
| 141 |
|
| 142 |
|
| 143 |
public IgnoreDependencyQuestions(boolean interactive) { |
| 144 |
this.interactive = interactive; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
private boolean containsPlugin(String[][] pluginDefinitions, Dependency plugin) { |
| 149 |
for (String[] pluginDefinition : pluginDefinitions) { |
| 150 |
if (!plugin.getGroupId().equals(pluginDefinition[0])) { |
| 151 |
continue; |
| 152 |
} |
| 153 |
if (plugin.getArtifactId().equals(pluginDefinition[1])) { |
| 154 |
return true; |
| 155 |
} |
| 156 |
} |
| 157 |
return false; |
| 158 |
} |
| 159 |
|
| 160 |
public boolean askIgnoreDependency(String sourcePomLoc, Dependency dependency, String message) { |
| 161 |
return askIgnoreDependency(sourcePomLoc, dependency, message, true); |
| 162 |
} |
| 163 |
|
| 164 |
private boolean askIgnoreDependency(String sourcePomLoc, Dependency dependency, String message, boolean defaultToIgnore) { |
| 165 |
if (notIgnoredDependencies.contains(dependency)) { |
| 166 |
return false; |
| 167 |
} |
| 168 |
if (!interactive) { |
| 169 |
return defaultToIgnore; |
| 170 |
} |
| 171 |
String question = "\n" + "In " + sourcePomLoc + ": " + message + " " + dependency; |
| 172 |
boolean ignore = new YesNoQuestion(question, defaultToIgnore).ask(); |
| 173 |
if (!ignore) { |
| 174 |
notIgnoredDependencies.add(dependency); |
| 175 |
} |
| 176 |
return ignore; |
| 177 |
} |
| 178 |
|
| 179 |
public boolean askIgnoreUnnecessaryDependency(Dependency dependency, String sourcePomLoc, |
| 180 |
boolean runTests, boolean generateJavadoc) { |
| 181 |
|
| 182 |
if (containsPlugin(DEPENDENCIES_TO_IGNORE, dependency) |
| 183 |
&& askIgnoreDependency(sourcePomLoc, dependency, |
| 184 |
"This dependency is now provided by the JRE. Ignore this dependency?")) |
| 185 |
return true; |
| 186 |
|
| 187 |
if (containsPlugin(PLUGINS_TO_IGNORE, dependency) |
| 188 |
&& askIgnoreDependency(sourcePomLoc, dependency, |
| 189 |
"This plugin is not useful for the build or its use is against Debian policies. Ignore this plugin?")) |
| 190 |
return true; |
| 191 |
|
| 192 |
if (containsPlugin(EXTENSIONS_TO_IGNORE, dependency) |
| 193 |
&& askIgnoreDependency(sourcePomLoc, dependency, |
| 194 |
"This extension is not useful for the build or its use is against Debian policies. Ignore this extension?")) |
| 195 |
return true; |
| 196 |
|
| 197 |
if (containsPlugin(PLUGINS_THAT_CAN_BE_IGNORED, dependency) |
| 198 |
&& askIgnoreDependency(sourcePomLoc, dependency, "This plugin may be ignored in some cases. Ignore this plugin?")) |
| 199 |
return true; |
| 200 |
|
| 201 |
if (!runTests) { |
| 202 |
if ("test".equals(dependency.getScope()) |
| 203 |
&& askIgnoreDependency(sourcePomLoc, dependency, "Tests are turned off. Ignore this test dependency?")) |
| 204 |
return true; |
| 205 |
if (containsPlugin(TEST_PLUGINS, dependency) |
| 206 |
&& askIgnoreDependency(sourcePomLoc, dependency, "Tests are turned off. Ignore this test plugin?")) |
| 207 |
return true; |
| 208 |
} |
| 209 |
// is Documentation Or Report Plugin? |
| 210 |
if (!generateJavadoc && containsPlugin(DOC_PLUGINS, dependency) |
| 211 |
&& askIgnoreDependency(sourcePomLoc, dependency, |
| 212 |
"Documentation is turned off. Ignore this documentation plugin?")) |
| 213 |
return true; |
| 214 |
|
| 215 |
return false; |
| 216 |
} |
| 217 |
|
| 218 |
public boolean askIgnoreDocOrReportPlugin(String sourcePomLoc, Dependency dependency) { |
| 219 |
return containsPlugin(DOC_PLUGINS, dependency) |
| 220 |
&& askIgnoreDependency(sourcePomLoc, dependency, |
| 221 |
"This documentation or report plugin cannot be found in the Maven repository for Debian. Ignore this plugin?"); |
| 222 |
} |
| 223 |
|
| 224 |
public String askIgnoreNeededDependency(String sourcePomLoc, Dependency dependency) { |
| 225 |
String type = dependency.isPlugin() ? "plugin" : "dependency"; |
| 226 |
String question = "This " + type + " cannot be found in the Debian Maven repository. Ignore this " + type + "?"; |
| 227 |
|
| 228 |
if (!askIgnoreDependency(sourcePomLoc, dependency, question, false)) { |
| 229 |
return sourcePomLoc + ": " + type + " is not packaged in the Maven repository for Debian: " + dependency.getGroupId() + ":" |
| 230 |
+ dependency.getArtifactId() + ":" + dependency.getVersion(); |
| 231 |
} |
| 232 |
return ""; |
| 233 |
} |
| 234 |
} |
| 235 |
|