org.apache.maven.plugins.shade.relocation.Relocator Java Examples

The following examples show how to use org.apache.maven.plugins.shade.relocation.Relocator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrefsResourceTransformer.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
@Override
public void processResource(String resource, InputStream is, List<Relocator> relocators) throws IOException {
	List<String> trandformedLines = new ArrayList<>();
	BufferedReader reader = new BufferedReader(new InputStreamReader(is));
	String line = reader.readLine();
	while (line != null) {
		trandformedLines.add(transformLine(line, relocators));
		line = reader.readLine();
	}
	this.transformedResources.put(resource, trandformedLines);
}
 
Example #2
Source File: PrefsResourceTransformer.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private String transformLine(String line, List<Relocator> relocators) {
	int splitIndex = line.lastIndexOf('=');
	if (splitIndex == -1) {
		return line;
	}
	String key = line.substring(0, splitIndex);
	String value = line.substring(splitIndex + 1);
	return relocateKey(key, relocators) + "=" + value;
}
 
Example #3
Source File: PrefsResourceTransformer.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private String relocateKey(String key, List<Relocator> relocators) {
	for (Relocator relocator : relocators) {
		if (relocator.canRelocateClass(key)) {
			return relocator.relocateClass(key);
		}
	}
	return key;
}
 
Example #4
Source File: PluginsCacheFileTransformer.java    From maven-shaded-log4j-transformer with Apache License 2.0 5 votes vote down vote up
public void processResource(String resource, InputStream is, List<Relocator> relocators) throws IOException {
    final File tempFile = File.createTempFile("Log4j2Plugins", "dat");
    FileOutputStream fos = new FileOutputStream(tempFile);
    try {
        IOUtils.copyLarge(is, fos);
    } finally {
        IOUtils.closeQuietly(fos);
    }
    tempFiles.add(tempFile);

    if (relocators != null) {
        this.relocators.addAll(relocators);
    }
}
 
Example #5
Source File: PluginsCacheFileTransformer.java    From maven-shaded-log4j-transformer with Apache License 2.0 5 votes vote down vote up
void relocatePlugin(PluginCache aggregator, List<Relocator> relocators) {
    for (Map.Entry<String, Map<String, PluginEntry>> categoryEntry : aggregator.getAllCategories().entrySet()) {
        for (Map.Entry<String, PluginEntry> pluginMapEntry : categoryEntry.getValue().entrySet()) {
            PluginEntry pluginEntry = pluginMapEntry.getValue();
            String originalClassName = pluginEntry.getClassName();

            Relocator matchingRelocator = findFirstMatchingRelocator(originalClassName, relocators);

            if (matchingRelocator != null) {
                String newClassName = matchingRelocator.relocateClass(originalClassName);
                pluginEntry.setClassName(newClassName);
            }
        }
    }
}
 
Example #6
Source File: PluginsCacheFileTransformer.java    From maven-shaded-log4j-transformer with Apache License 2.0 5 votes vote down vote up
private Relocator findFirstMatchingRelocator(String originalClassName, List<Relocator> relocators) {
    for (Relocator relocator : relocators) {
        if (relocator.canRelocateClass(originalClassName)) {
            return relocator;
        }
    }
    return null;
}
 
Example #7
Source File: PluginsCacheFileTransformerTest.java    From maven-shaded-log4j-transformer with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    PluginsCacheFileTransformer t = new PluginsCacheFileTransformer();
    final InputStream is = getClass().getClassLoader().getResourceAsStream(PLUGIN_CACHE_FILE);
    t.processResource(PLUGIN_CACHE_FILE, is, null);
    assertFalse(t.hasTransformedResource());

    List<Relocator> relocators = new ArrayList<Relocator>();
    relocators.add(new SimpleRelocator(null, null, null, null));
    t.processResource(PLUGIN_CACHE_FILE, is, relocators);
    assertTrue(t.hasTransformedResource());
}
 
Example #8
Source File: PluginsCacheFileTransformerTest.java    From maven-shaded-log4j-transformer with Apache License 2.0 5 votes vote down vote up
private void testRelocation(String src, String pattern, String target) throws IOException {
    PluginsCacheFileTransformer t = new PluginsCacheFileTransformer();
    Relocator log4jRelocator = new SimpleRelocator(src, pattern, null, null);
    PluginCache aggregator = new PluginCache();
    aggregator.loadCacheFiles(enumeration(singletonList(pluginUrl)));

    t.relocatePlugin(aggregator, singletonList(log4jRelocator));

    for (Map<String, PluginEntry> pluginEntryMap : aggregator.getAllCategories().values()) {
        for (PluginEntry entry : pluginEntryMap.values()) {
            assertTrue(entry.getClassName().startsWith(target));
        }
    }
}
 
Example #9
Source File: ArtifactTransformer.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public void processResource(final String resource, final InputStream is, final List<Relocator> relocators,
        final long time) throws IOException {
    // no-op
}