Skip to content

Commit 5e175d9

Browse files
committed
Completely remove pseudo-OSGi stuff.
- OSGI-INF -> ATPLUG-INF - .xml -> .json - Service-Component -> AtPlug-Component
1 parent d06f27c commit 5e175d9

6 files changed

Lines changed: 37 additions & 42 deletions

File tree

atplug-plugin-gradle/src/main/java/com/diffplug/atplug/tooling/PlugGenerator.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import kotlin.reflect.full.companionObjectInstance
3434
import kotlin.reflect.full.memberFunctions
3535

3636
class PlugGenerator internal constructor(toSearches: List<File>, toLinkAgainst: Set<File>) {
37-
@JvmField val osgiInf: SortedMap<String, String> = TreeMap()
37+
@JvmField val atplugInf: SortedMap<String, String> = TreeMap()
3838

3939
/** A cache from a plugin interface to a function that converts a class into its metadata. */
4040
private val metadataCreatorCache = mutableMapOf<Class<*>, Function<Class<*>, String>>()
@@ -91,8 +91,8 @@ class PlugGenerator internal constructor(toSearches: List<File>, toLinkAgainst:
9191
require(!Modifier.isAbstract(plugClass.modifiers)) {
9292
"Class $plugClass has @Plug($socketClass) but it is abstract."
9393
}
94-
val osgiInfContent = generatePlugin<Any, Any>(plugClass, socketClass)
95-
osgiInf[plugClass.name] = osgiInfContent
94+
val atplugInfContent = generatePlugin<Any, Any>(plugClass, socketClass)
95+
atplugInf[plugClass.name] = atplugInfContent
9696
}
9797

9898
private fun <SocketT, PlugT : SocketT> generatePlugin(
@@ -136,7 +136,7 @@ class PlugGenerator internal constructor(toSearches: List<File>, toLinkAgainst:
136136
val ext = PlugGeneratorJavaExecable(toSearch, toLinkAgainst)
137137
val metadataGen = PlugGenerator(ext.toSearch, ext.toLinkAgainst)
138138
// save our results, with no reference to the guts of what happened inside PluginMetadataGen
139-
metadataGen.osgiInf
139+
metadataGen.atplugInf
140140
} catch (e: Exception) {
141141
if (rootCause(e) is UnsatisfiedLinkError) {
142142
throw RuntimeException(

atplug-plugin-gradle/src/main/java/com/diffplug/atplug/tooling/PlugGeneratorJavaExecable.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public PlugGeneratorJavaExecable(List<File> toSearch, Set<File> toLinkAgainst) {
3838
}
3939

4040
// outputs
41-
SortedMap<String, String> osgiInf;
41+
SortedMap<String, String> atplugInf;
4242

43-
public SortedMap<String, String> getOsgiInf() {
44-
return osgiInf;
43+
public SortedMap<String, String> getAtplugInf() {
44+
return atplugInf;
4545
}
4646

4747
@Override
4848
public void run() {
4949
PlugGenerator metadataGen = new PlugGenerator(toSearch, toLinkAgainst);
50-
osgiInf = metadataGen.osgiInf;
50+
atplugInf = metadataGen.atplugInf;
5151
}
5252
}

atplug-plugin-gradle/src/main/java/com/diffplug/atplug/tooling/gradle/PlugGenerateTask.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public File getResourcesFolder() {
9999
}
100100

101101
@OutputDirectory
102-
public File getOsgiInfFolder() {
103-
return new File(resourcesFolder, PlugPlugin.OSGI_INF);
102+
public File getAtplugInfFolder() {
103+
return new File(resourcesFolder, PlugPlugin.ATPLUG_INF);
104104
}
105105

106106
@InputFiles
@@ -126,9 +126,9 @@ public void build() throws Throwable {
126126
SortedMap<String, String> result = generate();
127127

128128
// clean out the osgiInf folder, and put the map's content into the folder
129-
FileMisc.cleanDir(getOsgiInfFolder());
129+
FileMisc.cleanDir(getAtplugInfFolder());
130130
for (Map.Entry<String, String> entry : result.entrySet()) {
131-
File serviceFile = new File(getOsgiInfFolder(), entry.getKey() + PlugPlugin.DOT_XML);
131+
File serviceFile = new File(getAtplugInfFolder(), entry.getKey() + PlugPlugin.DOT_JSON);
132132
Files.write(serviceFile.toPath(), entry.getValue().getBytes(StandardCharsets.UTF_8));
133133
}
134134

@@ -190,15 +190,15 @@ private SortedMap<String, String> generate() throws Throwable {
190190
options.setExecutable(getLauncher().get().getExecutablePath());
191191
});
192192
});
193-
return JavaExecable.exec(workQueue, input).getOsgiInf();
193+
return JavaExecable.exec(workQueue, input).getAtplugInf();
194194
} else {
195195
input.run();
196-
return input.getOsgiInf();
196+
return input.getAtplugInf();
197197
}
198198
}
199199

200200
private String serviceComponents() {
201-
return serviceComponents(getOsgiInfFolder());
201+
return serviceComponents(getAtplugInfFolder());
202202
}
203203

204204
static String serviceComponents(File osgiInf) {
@@ -207,8 +207,8 @@ static String serviceComponents(File osgiInf) {
207207
} else {
208208
List<String> serviceComponents = new ArrayList<>();
209209
for (File file : FileMisc.list(osgiInf)) {
210-
if (file.getName().endsWith(PlugPlugin.DOT_XML)) {
211-
serviceComponents.add(PlugPlugin.OSGI_INF + file.getName());
210+
if (file.getName().endsWith(PlugPlugin.DOT_JSON)) {
211+
serviceComponents.add(PlugPlugin.ATPLUG_INF + file.getName());
212212
}
213213
}
214214
Collections.sort(serviceComponents);

atplug-plugin-gradle/src/main/java/com/diffplug/atplug/tooling/gradle/PlugPlugin.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
public class PlugPlugin implements Plugin<Project> {
4141
static final String GENERATE = "plugGenerate";
4242

43-
static final String SERVICE_COMPONENT = "Service-Component";
44-
static final String DOT_XML = ".xml";
45-
static final String OSGI_INF = "OSGI-INF/";
43+
static final String SERVICE_COMPONENT = "AtPlug-Component";
44+
static final String DOT_JSON = ".json";
45+
static final String ATPLUG_INF = "ATPLUG-INF/";
4646

4747
@Override
4848
public void apply(Project project) {
@@ -76,22 +76,22 @@ public void apply(Project project) {
7676
project.getTasks().named(JavaPlugin.JAR_TASK_NAME).configure(jarTaskUntyped -> {
7777
Jar jarTask = (Jar) jarTaskUntyped;
7878
PlugGenerateTask metadataTask = generateTask.get();
79-
jarTask.getInputs().dir(metadataTask.getOsgiInfFolder());
80-
jarTask.doFirst("Set " + PlugPlugin.SERVICE_COMPONENT + " header", new SetServiceComponentHeader(metadataTask.getOsgiInfFolder()));
79+
jarTask.getInputs().dir(metadataTask.getAtplugInfFolder());
80+
jarTask.doFirst("Set " + PlugPlugin.SERVICE_COMPONENT + " header", new SetServiceComponentHeader(metadataTask.getAtplugInfFolder()));
8181
});
8282
project.getTasks().named(JavaPlugin.PROCESS_RESOURCES_TASK_NAME).configure(t -> t.dependsOn(generateTask));
8383
}
8484

8585
static class SetServiceComponentHeader implements Serializable, Action<Task> {
86-
private final File osgiInfFolder;
86+
private final File atplugInfFolder;
8787

88-
SetServiceComponentHeader(File osgiInfFolder) {
89-
this.osgiInfFolder = osgiInfFolder;
88+
SetServiceComponentHeader(File atplugInfFolder) {
89+
this.atplugInfFolder = atplugInfFolder;
9090
}
9191

9292
@Override
9393
public void execute(Task task) {
94-
String serviceComponents = PlugGenerateTask.serviceComponents(osgiInfFolder);
94+
String serviceComponents = PlugGenerateTask.serviceComponents(atplugInfFolder);
9595
Jar jarTask = (Jar) task;
9696
if (serviceComponents == null) {
9797
jarTask.getManifest().getAttributes().remove(PlugPlugin.SERVICE_COMPONENT);

atplug-plugin-gradle/src/test/java/com/diffplug/atplug/tooling/gradle/PlugPluginTest.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ class PlugPluginTest : GradleIntegrationHarness() {
2828

2929
val copy = { str: String ->
3030
val src = File("../atplug-runtime/src/test/java/com/diffplug/atplug/$str")
31-
setFile("src/main/java/com/diffplug/atplug/$str").toContent(String(Files.readAllBytes(src.toPath()), StandardCharsets.UTF_8))
31+
setFile("src/main/java/com/diffplug/atplug/$str")
32+
.toContent(String(Files.readAllBytes(src.toPath()), StandardCharsets.UTF_8))
3233
}
3334
copy("Fruit.kt")
3435
copy("Shape.java")
3536

3637
gradleRunner().withArguments("jar", "--stacktrace").build()
3738

38-
assertFile("src/main/resources/OSGI-INF/com.diffplug.atplug.Apple.xml")
39+
assertFile("src/main/resources/ATPLUG-INF/com.diffplug.atplug.Apple.json")
3940
.hasContent(
4041
"{\n" +
4142
" \"implementation\": \"com.diffplug.atplug.Apple\",\n" +
@@ -44,7 +45,7 @@ class PlugPluginTest : GradleIntegrationHarness() {
4445
" \"id\": \"Apple\"\n" +
4546
" }\n" +
4647
"}")
47-
assertFile("src/main/resources/OSGI-INF/com.diffplug.atplug.Orange.xml")
48+
assertFile("src/main/resources/ATPLUG-INF/com.diffplug.atplug.Orange.json")
4849
.hasContent(
4950
"{\n" +
5051
" \"implementation\": \"com.diffplug.atplug.Orange\",\n" +
@@ -53,7 +54,7 @@ class PlugPluginTest : GradleIntegrationHarness() {
5354
" \"id\": \"Orange\"\n" +
5455
" }\n" +
5556
"}")
56-
assertFile("src/main/resources/OSGI-INF/com.diffplug.atplug.Shape\$Circle.xml")
57+
assertFile("src/main/resources/ATPLUG-INF/com.diffplug.atplug.Shape\$Circle.json")
5758
.hasContent(
5859
"{\n" +
5960
" \"implementation\": \"com.diffplug.atplug.Shape\$Circle\",\n" +
@@ -65,8 +66,8 @@ class PlugPluginTest : GradleIntegrationHarness() {
6566
assertFile("src/main/resources/META-INF/MANIFEST.MF")
6667
.hasContentIgnoreWhitespace(
6768
"Manifest-Version: 1.0\n" +
68-
"Service-Component: OSGI-INF/com.diffplug.atplug.Apple.xml,OSGI-INF/com.d\n" +
69-
" iffplug.atplug.Orange.xml,OSGI-INF/com.diffplug.atplug.Shape\$Circle.xml\n" +
70-
" ,OSGI-INF/com.diffplug.atplug.Shape\$Square.xml")
69+
"AtPlug-Component: ATPLUG-INF/com.diffplug.atplug.Apple.json,ATPLUG-INF/com.d\n" +
70+
" iffplug.atplug.Orange.json,ATPLUG-INF/com.diffplug.atplug.Shape\$Circle.json\n" +
71+
" ,ATPLUG-INF/com.diffplug.atplug.Shape\$Square.json")
7172
}
7273
}

atplug-runtime/src/main/java/com/diffplug/atplug/PlugRegistry.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ interface PlugRegistry {
3030
}
3131

3232
private const val PATH_MANIFEST = "META-INF/MANIFEST.MF"
33-
private const val DS_WITHIN_MANIFEST = "Service-Component"
33+
private const val DS_WITHIN_MANIFEST = "AtPlug-Component"
3434

3535
internal fun parseComponent(manifestUrl: String, servicePath: String): PlugDescriptor {
3636
val serviceUrl =
3737
URL(manifestUrl.substring(0, manifestUrl.length - PATH_MANIFEST.length) + servicePath)
3838

3939
val out = ByteArrayOutputStream()
40-
serviceUrl.openStream().use {
41-
it.copyTo(out)
42-
}
40+
serviceUrl.openStream().use { it.copyTo(out) }
4341
val serviceFileContent = String(out.toByteArray(), StandardCharsets.UTF_8)
4442
return PlugDescriptor.fromJson(serviceFileContent)
4543
}
@@ -72,12 +70,8 @@ interface PlugRegistry {
7270
for (service in
7371
services.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) {
7472
val servicePath = service.trim { it <= ' ' }
75-
if (!servicePath.isEmpty()) {
73+
if (servicePath.isNotEmpty()) {
7674
val asString = manifestUrl.toExternalForm()
77-
if (asString.contains("org.eclipse.core.contenttype")) {
78-
// causes noisy errors
79-
continue
80-
}
8175
val component = parseComponent(asString, servicePath)
8276
synchronized(this) {
8377
data.put(component.provides, component)

0 commit comments

Comments
 (0)