Skip to content

Commit

Permalink
Move all hardcoded code to single class
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Jul 25, 2024
1 parent 772e8c1 commit d12dcd5
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ public void execute(Project project) {

if (project.buildOptions().getTargetPath() != null) {
this.out.println("\t" + relativePathToExecutableString);
} else if (relativePathToExecutableString.contains("..")
|| relativePathToExecutableString.contains("." + File.separator)) {
this.out.println("\t" + executablePathString);
} else {
if (relativePathToExecutableString.contains("..")
|| relativePathToExecutableString.contains("." + File.separator)) {
this.out.println("\t" + executablePathString);
} else {
this.out.println("\t" + relativePathToExecutableString);
}
this.out.println("\t" + relativePathToExecutableString);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,10 @@ private static String getFunctionToMockClassName(String id) {
public static String getClassPath(JBallerinaBackend jBallerinaBackend, Package currentPackage) {
JarResolver jarResolver = jBallerinaBackend.jarResolver();

List<Path> dependencies = getTestDependencyPaths(currentPackage, jarResolver);

List<Path> jarList = getModuleJarPaths(jBallerinaBackend, currentPackage);
dependencies.removeAll(jarList);
dependencies.removeAll(jarResolver.optimizedJarLibraryPaths);
List<Path> dependencies = getTestDependencyPaths(currentPackage, jarResolver).stream()
.filter(each -> !jarList.contains(each) && !jarResolver.optimizedJarLibraryPaths.contains(each))
.toList();

StringJoiner classPath = joinClassPaths(dependencies);
return classPath.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public class JBallerinaBackend extends CompilerBackend {
private final UsedBIRNodeAnalyzer usedBIRNodeAnalyzer;
private final CodeGenOptimizationReportEmitter codeGenOptimizationReportEmitter;
private final Map<String, ByteArrayOutputStream> optimizedJarStreams;
protected final Set<PackageID> unusedCompilerLevelPackageIds;
protected final Set<PackageId> unusedProjectLevelPackageIds;
protected final Set<ModuleId> unusedModuleIds;
protected final Map<PackageId, Set<String>> pkgWiseUsedNativeClassPaths;
private final Set<PackageID> unusedCompilerLevelPackageIds;
final Set<PackageId> unusedProjectLevelPackageIds;
final Set<ModuleId> unusedModuleIds;
final Map<PackageId, Set<String>> pkgWiseUsedNativeClassPaths;

public static JBallerinaBackend from(PackageCompilation packageCompilation, JvmTarget jdkVersion) {
return from(packageCompilation, jdkVersion, true);
Expand Down Expand Up @@ -231,8 +231,7 @@ private void performCodeGen(boolean shrink) {
ModuleContext.shrinkDocuments(moduleContext);
}
// Codegen happens later when --optimize flag is active. We cannot clean the BlangPkgs until then.
if (!project.buildOptions().optimizeCodegen() &&
project.kind() == ProjectKind.BALA_PROJECT) {
if (!project.buildOptions().optimizeCodegen() && project.kind() == ProjectKind.BALA_PROJECT) {
moduleContext.cleanBLangPackage();
}
}
Expand Down Expand Up @@ -303,6 +302,7 @@ private void markCommonDependencies(BLangPackage bLangPackage) {
collectDependencies(bLangPackage.symbol, buildPkgDependencies);
collectDependencies(bLangPackage.getTestablePkg().symbol, testablePkgDependencies);

// FIXME: this filter should be applied only if env variable is not set?
buildPkgDependencies.stream()
.filter(testablePkgDependencies::contains).filter(pkgSymbol -> !isWhiteListedModule(pkgSymbol.pkgID))
.forEach(pkgSymbol -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.ballerina.projects.internal.DefaultDiagnosticResult;
import io.ballerina.projects.internal.PackageDiagnostic;
import io.ballerina.projects.internal.ProjectDiagnosticErrorCode;
import io.ballerina.projects.util.CodegenOptimizationUtils;
import io.ballerina.projects.util.ProjectConstants;
import io.ballerina.projects.util.ProjectUtils;
import io.ballerina.tools.diagnostics.Diagnostic;
Expand Down Expand Up @@ -48,10 +49,6 @@
import java.util.zip.ZipEntry;

import static io.ballerina.identifier.Utils.encodeNonFunctionIdentifier;
import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINAI_OBSERVE;
import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINAX;
import static io.ballerina.projects.util.CodegenOptimizationConstants.BALLERINA_OBSERVE;
import static io.ballerina.projects.util.CodegenOptimizationConstants.DOT_DRIVER;
import static io.ballerina.projects.util.ProjectConstants.ANON_ORG;
import static io.ballerina.projects.util.ProjectConstants.DOT;

Expand Down Expand Up @@ -264,7 +261,7 @@ private static boolean hasEmptyIdOrVersion(JarLibrary entry) {

private boolean isUsedDependency(JarLibrary otherJarDependency, Set<String> usedNativeClassPaths) {
String pkgName = otherJarDependency.packageName().orElseThrow();
if (isWhiteListedPkg(pkgName)) {
if (CodegenOptimizationUtils.isWhiteListedModule(pkgName)) {
return true;
}
if (usedNativeClassPaths.isEmpty()) {
Expand All @@ -283,16 +280,6 @@ private boolean isUsedDependency(JarLibrary otherJarDependency, Set<String> used
}
}

private boolean isWhiteListedPkg(String pkgName) {
return pkgName.equals(BALLERINA_OBSERVE) || pkgName.equals(BALLERINAI_OBSERVE) || isDriverPkg(pkgName);
}

// Driver pkgs are pkgs such as "ballerinax/mysql.driver".
// These pkgs contain only native jars without any source code.
private boolean isDriverPkg(String pkgName) {
return pkgName.startsWith(BALLERINAX) && pkgName.endsWith(DOT_DRIVER);
}

private void reportDiagnostic(JarLibrary existingEntry, JarLibrary newEntry) {
// Report diagnostic only for non ballerina dependencies
if (!existingEntry.packageName().orElseThrow().startsWith(ProjectConstants.BALLERINA_ORG)
Expand Down
Loading

0 comments on commit d12dcd5

Please sign in to comment.