Skip to content

Commit

Permalink
Enforce encapsulation of equinox-launcher Constants and JNIBridge
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Mar 25, 2024
1 parent a90c944 commit 4504ab2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 46 deletions.
1 change: 0 additions & 1 deletion bundles/org.eclipse.equinox.launcher/META-INF/MANIFEST.MF
Expand Up @@ -8,6 +8,5 @@ Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Localization: launcher
Export-Package: org.eclipse.core.launcher;x-internal:=true,
org.eclipse.equinox.internal.launcher;x-internal:=true,
org.eclipse.equinox.launcher;x-internal:=true
Automatic-Module-Name: org.eclipse.equinox.launcher
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 IBM Corporation and others.
* Copyright (c) 2006, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,12 +11,12 @@
* Contributors:
* Andrew Niefer - IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.internal.launcher;
package org.eclipse.equinox.launcher;

/**
* @author aniefer
*/
public class Constants {
class Constants {
public static final String INTERNAL_AMD64 = "amd64"; //$NON-NLS-1$
public static final String INTERNAL_OS_SUNOS = "SunOS"; //$NON-NLS-1$
public static final String INTERNAL_OS_LINUX = "Linux"; //$NON-NLS-1$
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 IBM Corporation and others.
* Copyright (c) 2006, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,8 +23,7 @@
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class JNIBridge {
//TODO: This class should not be public
class JNIBridge {
private native void _set_exit_data(String sharedId, String data);

private native void _set_launcher_info(String launcher, String name);
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -59,8 +59,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import org.eclipse.equinox.internal.launcher.Constants;

/**
* The launcher for Eclipse.
*
Expand Down
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* Umair Sair - initial API and implementation
*******************************************************************************/
package main;
package org.eclipse.equinox.launcher;

import java.io.BufferedReader;
import java.io.DataOutputStream;
Expand All @@ -31,11 +31,11 @@
* port and accepts following queries
* - -args - returns the arguments passed to this application. Test verify if the
* arguments are passed to application correctly by the launcher.
*
*
* And accepts following information
* - -exitdata - The exit data this application should set before exiting
* - -exitcode - The exit code with which this application should exit
*
*
* @author umairsair
*
*/
Expand Down Expand Up @@ -98,8 +98,9 @@ private static void communicateToServer() throws Exception {
out.flush();
} else if (TestLauncherConstants.EXITDATA_PARAMETER.equals(line)) {
while ((line = in.readLine()) != null) {
if (TestLauncherConstants.MULTILINE_ARG_VALUE_TERMINATOR.equals(line))
if (TestLauncherConstants.MULTILINE_ARG_VALUE_TERMINATOR.equals(line)) {
break;
}
exitData.add(line);
}
} else if (TestLauncherConstants.EXITCODE_PARAMETER.equals(line)) {
Expand Down
Expand Up @@ -11,7 +11,7 @@
* Contributors:
* Umair Sair - initial API and implementation
*******************************************************************************/
package main;
package org.eclipse.equinox.launcher;

public interface TestLauncherConstants {
public static final String ARGS_PARAMETER = "-args"; //$NON-NLS-1$
Expand Down
Expand Up @@ -20,42 +20,40 @@
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import org.eclipse.equinox.launcher.TestLauncherConstants;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import main.TestLauncherConstants;

public class LauncherTests {
private static final String ECLIPSE_INI_PATH_KEY = "ECLIPSE_INI_PATH";
// eclipse ini file name is relative to eclipse binary. e.g., in mac, it is ../Eclipse/eclipse.ini
// and on other hosts, it is present in same directory as eclipse binary
private static final String ECLIPSE_INI_FILE_NAME = System.getProperty(ECLIPSE_INI_PATH_KEY,
System.getenv(ECLIPSE_INI_PATH_KEY) == null ? "eclipse.ini" : System.getenv(ECLIPSE_INI_PATH_KEY));
// @formatter:off
private static final String DEFAULT_ECLIPSE_INI_CONTENT = "-startup\n"
+ "../test.launcher.jar\n"
+ "--launcher.library\n"
+ "plugins/org.eclipse.equinox.launcher\n"
+ "-vmargs\n"
+ "-Xms40m\n"
+ "";
// @formatter:on
public static final Integer EXIT_OK = Integer.valueOf(0);
public static final Integer EXIT_RESTART = Integer.valueOf(23);
public static final Integer EXIT_RELAUNCH = Integer.valueOf(24);
private static final String DEFAULT_ECLIPSE_INI_CONTENT = """
-startup
../test.launcher.jar
--launcher.library
plugins/org.eclipse.equinox.launcher
-Xms40m
-vmargs
""";
public static final Integer EXIT_OK = 0;
public static final Integer EXIT_RESTART = 23;
public static final Integer EXIT_RELAUNCH = 24;

private ServerSocket server;

Expand Down Expand Up @@ -121,8 +119,8 @@ void test_eclipseIniChangesShouldBePickedOnRestart() throws IOException {
appArgs2.remove(appArgs2.indexOf("-Dtest"));

// Convert backslashes to forward slashes before comparison so that all paths are consistent
assertEquals(appArgs1.stream().map(s -> s.replace('\\', '/')).collect(Collectors.toList()),
appArgs2.stream().map(s -> s.replace('\\', '/')).collect(Collectors.toList()));
assertEquals(appArgs1.stream().map(s -> s.replace('\\', '/')).toList(),
appArgs2.stream().map(s -> s.replace('\\', '/')).toList());
}

@Test
Expand Down Expand Up @@ -157,8 +155,8 @@ void test_eclipseIniChangesShouldBePickedOnRelaunch() throws IOException {
appArgs2.remove(appArgs2.indexOf("dir1"));

// Convert backslashes to forward slashes before comparison so that all paths are consistent
assertEquals(appArgs1.stream().map(s -> s.replace('\\', '/')).collect(Collectors.toList()),
appArgs2.stream().map(s -> s.replace('\\', '/')).collect(Collectors.toList()));
assertEquals(appArgs1.stream().map(s -> s.replace('\\', '/')).toList(),
appArgs2.stream().map(s -> s.replace('\\', '/')).toList());
}

@Test
Expand Down Expand Up @@ -490,8 +488,8 @@ void test_ArgsRemainSameOverRestarts() throws IOException {
appArgs2.remove(appArgs2.indexOf(TestLauncherConstants.EXITDATA_PARAMETER) + 1);

// Convert backslashes to forward slashes before comparison so that all paths are consistent
assertEquals(appArgs1.stream().map(s -> s.replace('\\', '/')).collect(Collectors.toList()),
appArgs2.stream().map(s -> s.replace('\\', '/')).collect(Collectors.toList()));
assertEquals(appArgs1.stream().map(s -> s.replace('\\', '/')).toList(),
appArgs2.stream().map(s -> s.replace('\\', '/')).toList());
}
}

Expand All @@ -516,8 +514,8 @@ void test_ArgsRemainSameOverRelaunches() throws IOException {
appArgs2.remove(appArgs2.indexOf(TestLauncherConstants.EXITDATA_PARAMETER) + 1);

// Convert backslashes to forward slashes before comparison so that all paths are consistent
assertEquals(appArgs1.stream().map(s -> s.replace('\\', '/')).collect(Collectors.toList()),
appArgs2.stream().map(s -> s.replace('\\', '/')).collect(Collectors.toList()));
assertEquals(appArgs1.stream().map(s -> s.replace('\\', '/')).toList(),
appArgs2.stream().map(s -> s.replace('\\', '/')).toList());
}
}

Expand All @@ -530,16 +528,18 @@ private void analyzeLaunchedTestApp(Socket socket, List<String> appArgs, String
String line = null;
System.out.println("--- start ----");
while ((line = in.readLine()) != null) {
if (TestLauncherConstants.MULTILINE_ARG_VALUE_TERMINATOR.equals(line))
if (TestLauncherConstants.MULTILINE_ARG_VALUE_TERMINATOR.equals(line)) {
break;
}
System.out.println(line);
appArgs.add(line);
}
System.out.println("--- end ----");
{
out.writeBytes(TestLauncherConstants.EXITDATA_PARAMETER + "\n");
if (restartArgs != null && !restartArgs.isBlank())
if (restartArgs != null && !restartArgs.isBlank()) {
out.writeBytes(restartArgs + "\n");
}
out.writeBytes(TestLauncherConstants.MULTILINE_ARG_VALUE_TERMINATOR + "\n");
out.flush();

Expand All @@ -562,11 +562,7 @@ private Process startEclipseLauncher(List<String> args) throws IOException {
}

private void writeEclipseIni(String content) throws IOException {
File iniFile = new File(ECLIPSE_INI_FILE_NAME);
iniFile.createNewFile();
FileWriter myWriter = new FileWriter(ECLIPSE_INI_FILE_NAME);
myWriter.write(content);
myWriter.close();
Files.writeString(Path.of(ECLIPSE_INI_FILE_NAME), content);
}

}

0 comments on commit 4504ab2

Please sign in to comment.