-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
back pick trustin/os-maven-plugin#74
Signed-off-by: tison <wander4096@gmail.com>
- Loading branch information
Showing
4 changed files
with
135 additions
and
11 deletions.
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
80 changes: 80 additions & 0 deletions
80
plugin-maven/src/main/java/com/tisonkun/os/maven/DetectPropertyContributor.java
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.tisonkun.os.maven; | ||
|
||
import com.tisonkun.os.core.Detector; | ||
import com.tisonkun.os.core.FileOperationProvider; | ||
import com.tisonkun.os.core.SystemPropertyOperationProvider; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import javax.inject.Inject; | ||
import org.apache.maven.api.spi.PropertyContributor; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
import org.codehaus.plexus.logging.Logger; | ||
|
||
@Component(role = PropertyContributor.class) | ||
public class DetectPropertyContributor implements PropertyContributor { | ||
|
||
private final Logger logger; | ||
|
||
@Inject | ||
DetectPropertyContributor(Logger logger) { | ||
super(); | ||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public void contribute(Map<String, String> map) { | ||
DetectExtension.disable(); | ||
|
||
final Properties props = new Properties(); | ||
props.putAll(map); | ||
|
||
final Detector detector = | ||
new Detector(new SimpleSystemPropertyOperations(map), new SimpleFileOperations(), logger::info); | ||
detector.detect(props, getClassifierWithLikes(map)); | ||
} | ||
|
||
/** | ||
* Inspects the session's user and project properties for the {@link | ||
* DetectMojo#CLASSIFIER_WITH_LIKES_PROPERTY} and separates the property into a list. | ||
*/ | ||
private static List<String> getClassifierWithLikes(Map<String, String> map) { | ||
// Check to see if the project defined the | ||
return DetectMojo.getClassifierWithLikes(map.get(DetectMojo.CLASSIFIER_WITH_LIKES_PROPERTY)); | ||
} | ||
|
||
private static class SimpleSystemPropertyOperations implements SystemPropertyOperationProvider { | ||
final Map<String, String> map; | ||
|
||
private SimpleSystemPropertyOperations(Map<String, String> map) { | ||
this.map = map; | ||
} | ||
|
||
@Override | ||
public String getSystemProperty(String name) { | ||
return System.getProperty(name); | ||
} | ||
|
||
@Override | ||
public String getSystemProperty(String name, String def) { | ||
return System.getProperty(name, def); | ||
} | ||
|
||
@Override | ||
public String setSystemProperty(String name, String value) { | ||
map.put(name, value); | ||
return System.setProperty(name, value); | ||
} | ||
} | ||
|
||
private static class SimpleFileOperations implements FileOperationProvider { | ||
@Override | ||
public InputStream readFile(String fileName) throws IOException { | ||
return Files.newInputStream(Paths.get(fileName)); | ||
} | ||
} | ||
} |
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
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