-
-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Add a numberThreads
parameter.
#133
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5630afa
feature: Add a `numberThreads` parameter.
rhuss 245c079
Merge branch 'master' into allow-fixed-nr-thread
mathieucarbou 240e8bf
Merge branch 'master' into allow-fixed-nr-thread
mathieucarbou 18920e8
Merge branch 'master' into allow-fixed-nr-thread
mathieucarbou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,18 @@ public abstract class AbstractLicenseMojo extends AbstractMojo { | |
@Parameter(property = "license.concurrencyFactor", defaultValue = "1.5") | ||
public float concurrencyFactor = 1.5f; | ||
|
||
|
||
/** | ||
* Maven license plugin uses concurrency to check license headers. With this | ||
* option the number of threads used to check can be specified. If given | ||
* it take precedence over <code>concurrencyFactor</code> | ||
* | ||
* The default is 0 which implies that the default for <code>concurrencyFactor</code> | ||
* is used. | ||
*/ | ||
@Parameter(property = "license.numberThreads", defaultValue = "0") | ||
public int numberThreads; | ||
|
||
/** | ||
* Whether to skip the plugin execution | ||
*/ | ||
|
@@ -263,7 +275,7 @@ public abstract class AbstractLicenseMojo extends AbstractMojo { | |
*/ | ||
@Parameter(property = "license.skipExistingHeaders", defaultValue = "false") | ||
public boolean skipExistingHeaders = false; | ||
|
||
@Component | ||
public MavenProject project; | ||
|
||
|
@@ -277,22 +289,22 @@ public abstract class AbstractLicenseMojo extends AbstractMojo { | |
*/ | ||
@Component | ||
private SettingsDecrypter settingsDecrypter; | ||
|
||
private ResourceFinder finder; | ||
|
||
protected abstract class AbstractCallback implements Callback { | ||
|
||
/** | ||
* Related to {@link #failIfUnknown}. | ||
*/ | ||
private final Collection<File> unknownFiles = new ConcurrentLinkedQueue<File>(); | ||
|
||
@Override | ||
public void onUnknownFile(Document document, Header header) { | ||
warn("Unknown file extension: %s", document.getFilePath()); | ||
unknownFiles.add(document.getFile()); | ||
} | ||
|
||
public void checkUnknown() throws MojoExecutionException { | ||
if (!unknownFiles.isEmpty()) { | ||
String msg = "Unable to find a comment style definition for some " | ||
|
@@ -303,9 +315,9 @@ public void checkUnknown() throws MojoExecutionException { | |
getLog().warn(msg); | ||
} | ||
} | ||
|
||
} | ||
|
||
@SuppressWarnings({"unchecked"}) | ||
public final void execute(final Callback callback) throws MojoExecutionException, MojoFailureException { | ||
if (!skip) { | ||
|
@@ -317,7 +329,7 @@ public final void execute(final Callback callback) throws MojoExecutionException | |
warn("Property 'strictCheck' is not enabled. Please consider adding <strictCheck>true</strictCheck> in your pom.xml file."); | ||
warn("See http://mycila.github.io/license-maven-plugin for more information."); | ||
} | ||
|
||
finder = new ResourceFinder(basedir); | ||
try { | ||
finder.setCompileClassPath(project.getCompileClasspathElements()); | ||
|
@@ -338,7 +350,7 @@ public final void execute(final Callback callback) throws MojoExecutionException | |
final HeaderSource validHeaderSource = HeaderSource.of(null, validHeader, this.encoding, this.finder); | ||
validHeaders.add(new Header(validHeaderSource, headerSections)); | ||
} | ||
|
||
final List<PropertiesProvider> propertiesProviders = new LinkedList<PropertiesProvider>(); | ||
for (PropertiesProvider provider : ServiceLoader.load(PropertiesProvider.class, Thread.currentThread().getContextClassLoader())) { | ||
propertiesProviders.add(provider); | ||
|
@@ -347,7 +359,7 @@ public final void execute(final Callback callback) throws MojoExecutionException | |
@Override | ||
public Properties load(Document document) { | ||
Properties props = new Properties(); | ||
|
||
for (Map.Entry<String, String> entry : mergeProperties(document).entrySet()) { | ||
if (entry.getValue() != null) { | ||
props.setProperty(entry.getKey(), entry.getValue()); | ||
|
@@ -375,15 +387,15 @@ public Properties load(Document document) { | |
return props; | ||
} | ||
}; | ||
|
||
final DocumentFactory documentFactory = new DocumentFactory(basedir, buildMapping(), buildHeaderDefinitions(), encoding, keywords, propertiesLoader); | ||
|
||
int nThreads = (int) (Runtime.getRuntime().availableProcessors() * concurrencyFactor); | ||
int nThreads = getNumberOfExecutorThreads(); | ||
ExecutorService executorService = Executors.newFixedThreadPool(nThreads); | ||
CompletionService completionService = new ExecutorCompletionService(executorService); | ||
int count = 0; | ||
debug("Number of execution threads: %s", nThreads); | ||
|
||
try { | ||
for (final String file : listSelectedFiles()) { | ||
completionService.submit(new Runnable() { | ||
|
@@ -413,7 +425,7 @@ public void run() { | |
}, null); | ||
count++; | ||
} | ||
|
||
while (count-- > 0) { | ||
try { | ||
completionService.take().get(); | ||
|
@@ -436,13 +448,25 @@ public void run() { | |
throw new RuntimeException(cause.getMessage(), cause); | ||
} | ||
} | ||
|
||
} finally { | ||
executorService.shutdownNow(); | ||
} | ||
} | ||
} | ||
|
||
|
||
private int getNumberOfExecutorThreads() { | ||
int nThreads = numberThreads; | ||
if (nThreads != 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you validating against negative numbers? |
||
return nThreads; | ||
} | ||
nThreads = (int) (Runtime.getRuntime().availableProcessors() * concurrencyFactor); | ||
if (nThreads != 0) { | ||
return nThreads; | ||
} | ||
return 1; | ||
} | ||
|
||
private Map<String, String> mergeProperties(Document document) { | ||
// first put systen environment | ||
Map<String, String> props = new LinkedHashMap<String, String>(System.getenv()); | ||
|
@@ -466,15 +490,15 @@ private Map<String, String> mergeProperties(Document document) { | |
} | ||
return props; | ||
} | ||
|
||
private String[] listSelectedFiles() { | ||
Selection selection = new Selection(basedir, includes, buildExcludes(), useDefaultExcludes); | ||
debug("From: %s", basedir); | ||
debug("Including: %s", deepToString(selection.getIncluded())); | ||
debug("Excluding: %s", deepToString(selection.getExcluded())); | ||
return selection.getSelectedFiles(); | ||
} | ||
|
||
private String[] buildExcludes() { | ||
List<String> ex = new ArrayList<String>(); | ||
ex.addAll(asList(this.excludes)); | ||
|
@@ -485,25 +509,25 @@ private String[] buildExcludes() { | |
} | ||
return ex.toArray(new String[ex.size()]); | ||
} | ||
|
||
public final void info(String format, Object... params) { | ||
if (!quiet) { | ||
getLog().info(format(format, params)); | ||
} | ||
} | ||
|
||
public final void debug(String format, Object... params) { | ||
if (!quiet) { | ||
getLog().debug(format(format, params)); | ||
} | ||
} | ||
|
||
public final void warn(String format, Object... params) { | ||
if (!quiet) { | ||
getLog().warn(format(format, params)); | ||
} | ||
} | ||
|
||
private Map<String, String> buildMapping() { | ||
Map<String, String> extensionMapping = new LinkedHashMap<String, String>(); | ||
// force inclusion of unknow item to manage unknown files | ||
|
@@ -520,7 +544,7 @@ private Map<String, String> buildMapping() { | |
} | ||
return extensionMapping; | ||
} | ||
|
||
private Map<String, HeaderDefinition> buildHeaderDefinitions() throws MojoFailureException { | ||
// like mappings, first get default definitions | ||
final Map<String, HeaderDefinition> headers = new HashMap<String, HeaderDefinition>(HeaderType.defaultDefinitions()); | ||
|
@@ -563,18 +587,18 @@ List<Server> getDecryptedServers() { | |
*/ | ||
public Credentials findCredentials(String serverID) { | ||
List<Server> decryptedServers = getDecryptedServers(); | ||
|
||
for (Server ds : decryptedServers) { | ||
if (ds.getId().equals(serverID)) { | ||
getLog().debug("credentials have been found for server: " + serverID + ", login:" + ds.getUsername() + ", password:" + starEncrypt(ds.getPassword())); | ||
return new Credentials(ds.getUsername(), ds.getPassword()); | ||
} | ||
} | ||
|
||
getLog().debug("no credentials found for server: " + serverID); | ||
return null; | ||
} | ||
|
||
static String starEncrypt(String str) { | ||
if (str == null) { | ||
return null; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be documented in the README