10000 Make Java SDK based on IndeterminateSDKDescription · sakerbuild/saker.java.compiler@e4edcb4 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4edcb4

Browse files
committed
Make Java SDK based on IndeterminateSDKDescription
1 parent af8092e commit e4edcb4

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package saker.java.compiler.impl.sdk;
2+
3+
import java.io.Externalizable;
4+
import java.io.IOException;
5+
import java.io.ObjectInput;
6+
import java.io.ObjectOutput;
7+
8+
import saker.build.thirdparty.saker.util.ImmutableUtils;
9+
import saker.build.thirdparty.saker.util.io.SerialUtils;
10+
import saker.sdk.support.api.EnvironmentSDKDescription;
11+
import saker.sdk.support.api.IndeterminateSDKDescription;
12+
import saker.sdk.support.api.SDKDescription;
13+
import saker.sdk.support.api.SDKReference;
14+
import saker.sdk.support.api.exc.SDKPropertyNotFoundException;
15+
16+
public class JavaSDKDescription implements IndeterminateSDKDescription, Externalizable {
17+
private static final long serialVersionUID = 1L;
18+
19+
private SDKDescription baseSDK;
20+
21+
/**
22+
* For {@link Externalizable}.
23+
*/
24+
public JavaSDKDescription() {
25+
}
26+
27+
public JavaSDKDescription(SDKDescription baseSDK) {
28+
this.baseSDK = baseSDK;
29+
}
30+
31+
@Override
32+
public SDKDescription getBaseSDKDescription() {
33+
return baseSDK;
34+
}
35+
36+
@Override
37+
public SDKDescription pinSDKDescription(SDKReference sdkreference) {
38+
String prop = null;
39+
try {
40+
prop = sdkreference.getProperty(JavaSDKReference.PROPERTY_JAVA_VERSION);
41+
if (prop == null) {
42+
throw new SDKPropertyNotFoundException(
43+
JavaSDKReference.PROPERTY_JAVA_VERSION + " property not found in Java SDK.");
44+
}
45+
} catch (SDKPropertyNotFoundException e) {
46+
throw e;
47+
} catch (Exception e) {
48+
throw new SDKPropertyNotFoundException(
49+
JavaSDKReference.PROPERTY_JAVA_VERSION + " property not found in Java SDK.", e);
50+
}
51+
return EnvironmentSDKDescription
52+
.create(new JavaSDKReferenceEnvironmentProperty(ImmutableUtils.singletonNavigableSet(prop)));
53+
}
54+
55+
@Override
56+
public void writeExternal(ObjectOutput out) throws IOException {
57+
out.writeObject(baseSDK);
58+
}
59+
60+
@Override
61+
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
62+
baseSDK = SerialUtils.readExternalObject(in);
63+
}
64+
65+
@Override
66+
public int hashCode() {
67+
final int prime = 31;
68+
int result = 1;
69+
result = prime * result + ((baseSDK == null) ? 0 : baseSDK.hashCode());
70+
return result;
71+
}
72+
73+
@Override
74+
public boolean equals(Object obj) {
75+
if (this == obj)
76+
return true;
77+
if (obj == null)
78+
return false;
79+
if (getClass() != obj.getClass())
80+
return false;
81+
JavaSDKDescription other = (JavaSDKDescription) obj;
82+
if (baseSDK == null) {
83+
if (other.baseSDK != null)
84+
return false;
85+
} else if (!baseSDK.equals(other.baseSDK))
86+
return false;
87+
return true;
88+
}
89+
90+
@Override
91+
public String toString() {
92+
return "JavaSDKDescription[" + baseSDK + "]";
93+
}
94+
95+
}

impl/src/main/saker/java/compiler/impl/sdk/JavaSDKReference.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class JavaSDKReference implements SDKReference, Externalizable {
3434

3535
public static final String DEFAULT_SDK_NAME = SakerJavaCompilerUtils.DEFAULT_SDK_NAME;
3636

37+
public static final String PATH_HOME = SakerJavaCompilerUtils.JAVASDK_PATH_HOME;
3738
public static final String PATH_INSTALL_LOCATION = SakerJavaCompilerUtils.JAVASDK_PATH_INSTALL_LOCATION;
3839
public static final String PATH_JAVA_EXE = SakerJavaCompilerUtils.JAVASDK_PATH_JAVA_EXE;
3940

@@ -118,6 +119,7 @@ public SakerPath getPath(String identifier) throws Exception {
118119
return installLocation.resolve(relativeDefaultPlatformInclude);
119120
}
120121

122+
case PATH_HOME:
121123
case PATH_INSTALL_LOCATION: {
122124
return installLocation;
123125
}

main/src/main/saker/java/compiler/main/sdk/JavaSDKTaskFactory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import saker.build.task.utils.annot.SakerInput;
2727
import saker.build.trace.BuildTrace;
2828
import saker.java.compiler.impl.sdk.CurrentJavaSDKReferenceEnvironmentProperty;
29+
import saker.java.compiler.impl.sdk.JavaSDKDescription;
2930
import saker.java.compiler.impl.sdk.JavaSDKReferenceEnvironmentProperty;
3031
import saker.java.compiler.main.TaskDocs.JavaVersionOption;
3132
import saker.java.compiler.main.compile.JavaCompilerTaskFactory;
@@ -70,7 +71,8 @@ public Object run(TaskContext taskcontext) throws Exception {
7071
BuildTrace.classifyTask(BuildTrace.CLASSIFICATION_CONFIGURATION);
7172
}
7273
if (this.versionOption == null) {
73-
return EnvironmentSDKDescription.create(CurrentJavaSDKReferenceEnvironmentProperty.INSTANCE);
74+
return new JavaSDKDescription(
75+
EnvironmentSDKDescription.create(CurrentJavaSDKReferenceEnvironmentProperty.INSTANCE));
7476
}
7577
Collection<String> versions = this.versionOption.get();
7678
if (versions == null) {
@@ -88,7 +90,8 @@ public Object run(TaskContext taskcontext) throws Exception {
8890
taskcontext.abortExecution(new IllegalArgumentException("No suitable versions specified."));
8991
return null;
9092
}
91-
return EnvironmentSDKDescription.create(new JavaSDKReferenceEnvironmentProperty(suitableversions));
93+
return new JavaSDKDescription(
94+
EnvironmentSDKDescription.create(new JavaSDKReferenceEnvironmentProperty(suitableversions)));
9295
}
9396
};
9497
}

0 commit comments

Comments
 (0)
0