Skip to content

Commit

Permalink
Init Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaAlbanese committed Oct 10, 2022
1 parent 26b343e commit a96d971
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**A simple launcher for new JDK projects develop for provide Vassembler**

We provide this launcher to turn the process of use Vassembler (jar) as simple as possible.

*This launcher requires only a normal Java version (at Least 1.8)*

If needed this launcher download the right JDK version from the OpenJDK Website. For more info visit [jdk.java.net](https://jdk.java.net)

### Why?

Vassembler require a new JDK version that a lot of Java users don't have on their devices. We provide a simple way to use Vassembler without change the system Java version or ask the end user to download and install the new version of Java with all related problems.

NOTE: If you wish, you can still download Vassembler as a simple jar and launch it with the right JDK without use this launcher.
30 changes: 30 additions & 0 deletions Vassembler_Launcher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
71 changes: 71 additions & 0 deletions Vassembler_Launcher/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.altervista.logisim</groupId>
<artifactId>Vassembler_Launcher</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>Vassembler_Launcher</name>
<description>A simple launcher for Vassembler</description>
<url>https://logisim.altervista.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.rauschig</groupId>
<artifactId>jarchivelib</artifactId>
<version>0.7.1</version>
<type>jar</type>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>

<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.altervista.logisim.Vassembler_Launcher.Main</mainClass>
</manifest>
</archive>
</configuration>

<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>

</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.altervista.logisim.Vassembler_Launcher;

import javax.swing.JOptionPane;

public class Logger {

public static void log(String text){
JOptionPane.showMessageDialog(null, text,
"Error", JOptionPane.ERROR_MESSAGE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.altervista.logisim.Vassembler_Launcher;

import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.SystemUtils;

public class Main {

public static void main(String[] args) {
Utils.copyJAR();
// Check if is already satisfied
if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_10)) {
// Launch Vassembler with system JAVA
Utils.launchRealJAR(false);
} else {
// Check if JDK is in USER_HOME/.Vassembler and download it if not
Utils.getJDK();
Utils.launchRealJAR(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
package org.altervista.logisim.Vassembler_Launcher;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.lang3.SystemUtils;
import org.rauschig.jarchivelib.ArchiveFormat;
import org.rauschig.jarchivelib.Archiver;
import org.rauschig.jarchivelib.ArchiverFactory;
import org.rauschig.jarchivelib.CompressionType;

public class Utils {
static final String JDK_VERSION = "openjdk-18.0.1.1";
static final String DOT_VASSEMBLER_PATH = System.getProperty("user.home")+File.separator+".Vassembler";
static final String JDK_PATH = DOT_VASSEMBLER_PATH+File.separator+JDK_VERSION;
static final String JDK_TEMP_ZIP_PATH = getTempDir();
static final String JDK_JAVA_PATH = JDK_PATH+File.separator+"jdk-18.0.1.1"+File.separator+"bin"+File.separator+"java";
static final String JDK_DOWNLOAD_MAIN_URL = "https://download.java.net/java/GA/jdk18.0.1.1/65ae32619e2f40f3a9af3af1851d6e19/2/GPL/"+JDK_VERSION+"_";
static final String JAR_PATH = DOT_VASSEMBLER_PATH+File.separator+"Vassembler.jar";

public static String getTempDir() {
String tempDirString = System.getProperty("java.io.tmpdir");
if(!tempDirString.endsWith(File.separator)){
tempDirString = tempDirString + File.separator;
}
tempDirString = tempDirString + JDK_VERSION;
return tempDirString;
}

/**
* Detect System OS and return the download URL from download.java.net
* @return Object[URL, (boolean)isTarGZ]
*/
public static Object[] getURLForOS(){
Object[] returnObjects = new Object[2];
try {
if (SystemUtils.IS_OS_WINDOWS){
returnObjects[0] = new URL(JDK_DOWNLOAD_MAIN_URL+"windows-x64_bin.zip");
returnObjects[1] = false;
return returnObjects;
}
else if (SystemUtils.IS_OS_MAC){
// TODO: Manage macOS / AArch64
returnObjects[0] = new URL(JDK_DOWNLOAD_MAIN_URL + "macos-x64_bin.tar.gz");
returnObjects[1] = true;
return returnObjects;
}
else if(SystemUtils.IS_OS_LINUX){
System.out.println("Linux");
// TODO: Manage Linux / AArch64
returnObjects[0] = new URL(JDK_DOWNLOAD_MAIN_URL + "linux-x64_bin.tar.gz");
returnObjects[1] = true;
return returnObjects;
}
else
return null;
} catch (MalformedURLException ex) {
Logger.log(ex.toString());
return null;
}
}

/**
* Download and extract from a defined URL in the defined JDK_TEMP_ZIP_PATH
* @param url Download URL
* @param isTarGz
*/
public static void downloadFromURL(URL url,boolean isTarGz){
String archiveFileURLString = JDK_TEMP_ZIP_PATH;
if (isTarGz)
archiveFileURLString = archiveFileURLString + ".tar.gz";
else
archiveFileURLString = archiveFileURLString + ".zip";

// Download from URL
try {
BufferedInputStream inputStream = new BufferedInputStream(url.openStream());
FileOutputStream fileOS = new FileOutputStream(archiveFileURLString);
byte data[] = new byte[1024];
int byteContent;
while ((byteContent = inputStream.read(data, 0, 1024)) != -1) {
fileOS.write(data, 0, byteContent);
}
fileOS.close();
} catch (IOException ex){
Logger.log(ex.toString());
}

// Extract downloaded ZIP
try {
Archiver archiver = null;
if (isTarGz)
archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);
else
archiver = ArchiverFactory.createArchiver(ArchiveFormat.ZIP);

File source = new File(archiveFileURLString);
File destination = new File(JDK_PATH);
archiver.extract(source, destination);
source.delete();
} catch (IOException ex) {
Logger.log(ex.toString());
}
}

/**
* Check if JDK exist in JDK_PATH and download it if missing
*/
public static void getJDK() {
Path jdkPath = Paths.get(JDK_PATH);
if (!Files.exists(jdkPath)){
Object[] urlForOS = getURLForOS();
downloadFromURL((URL)urlForOS[0],(Boolean)urlForOS[1]);
}
}

/**
* Copy Vassembler JAR from this JAR to JAR_PATH
*/
public static void copyJAR() {
try {
Path destination = Paths.get(JAR_PATH);
if (Files.exists(destination))
return;
if (!Files.exists(destination.getParent()))
new File(DOT_VASSEMBLER_PATH).mkdirs();
InputStream source = Main.class.getResourceAsStream("/Vassembler.jar");
Files.copy(source, destination);
} catch (IOException ex) {
// TODO: handle errors
Logger.log(ex.toString());
}
}

/**
* Launch the JAR via system terminal
* @param portable if the java location is JDK_JAVA_PATH
*/
public static void launchRealJAR(boolean portable) {
String javaLocation = null;
if (portable){
javaLocation = JDK_JAVA_PATH;
if (SystemUtils.IS_OS_WINDOWS)
javaLocation = javaLocation + ".exe";
}else
javaLocation = "java";
try {
String launchCommand = javaLocation + " -jar " + JAR_PATH;
System.out.println(launchCommand);
Runtime.getRuntime().exec(launchCommand);

} catch (IOException ex) {
Logger.log("Can't launch the JAR " + ex.toString());
}
}


}
Binary file not shown.
Binary file added Workflow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a96d971

Please sign in to comment.