Added java project generator

This commit is contained in:
itdominator 2024-01-22 22:01:14 -06:00
parent 6bf66c5916
commit 93cde0000d
3 changed files with 236 additions and 0 deletions

View File

@ -0,0 +1,127 @@
#!/bin/bash
function createJavaData() {
createMainClassData "${PACKAGE}";
createControlClass "${PACKAGE}"
createLoggerClassData "${PACKAGE}";
createFXMLData "${PACKAGE}";
}
function createControlClass() {
read -d '' CONTROLCLASS << EOF
package com.${COMPANYNAME,,}.${PACKAGE,,};
import javafx.fxml.FXML;
public class Controller {
// Classes
// FXML Stuff
// Generics
@FXML void initialize() {
}
}
EOF
echo "${CONTROLCLASS}" > "${PACKAGE}"/src/Controller.java
}
function createMainClassData() {
read -d '' MAINCLASS << EOF
package com.${COMPANYNAME,,}.${PACKAGE,,};
import com.${COMPANYNAME,,}.${PACKAGE,,}.utils.${PACKAGE}Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import java.util.logging.Level;
import java.io.IOException;
public class ${PACKAGE} extends Application {
// Classes
private ${PACKAGE}Logger ${PACKAGE,,}Logger = ${PACKAGE}Logger.getInstance();
@Override public void start(Stage stage) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource(\"resources/${PACKAGE}.fxml\"));
loader.setController(new Controller());
loader.load();
Scene scene = new Scene(loader.getRoot());
scene.getStylesheets().add(\"/com/${COMPANYNAME}/${PACKAGE,,}/resources/stylesheet.css\");
stage.setTitle(\"${PACKAGE}\");
stage.setScene(scene);
} catch (IOException startException) {
String message = "\\\n${PACKAGE} Failed to launch...\\\n";
System.out.println(message + startException);
${PACKAGE,,}Logger.insertToLog(Level.SEVERE, message, startException);
}
// stage.getIcons().add(new Image(${PACKAGE}.class.getResourceAsStream(\"resources/${PACKAGE}.png\")));
stage.setResizable(true);
stage.show();
}
public static void main(String[] args) { launch(args); }
}
EOF
echo "${MAINCLASS}" > "${PACKAGE}"/src/"${PACKAGE}".java
}
function createLoggerClassData() {
read -d '' LOGGERCLASS << EOF
package com.${COMPANYNAME,,}.${PACKAGE,,}.utils;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.logging.FileHandler;
import java.io.IOException;
public class ${PACKAGE}Logger {
private static ${PACKAGE}Logger ${PACKAGE,,}Logger = new ${PACKAGE}Logger();
private Logger logger = Logger.getLogger(${PACKAGE}Logger.class.getName());
private boolean append = false;
// Instance passer
public static ${PACKAGE}Logger getInstance() { return ${PACKAGE,,}Logger; }
// Init ${PACKAGE}Logger
private ${PACKAGE}Logger() {
try {
FileHandler logFile = new FileHandler(\"${PACKAGE,,}_error.log\", append);
logger.addHandler(logFile);
} catch (IOException e) {
insertToLog(Level.SEVERE, \"Can not access error log file...\", e);
e.printStackTrace();
}
}
public void insertToLog(Level severity, String message, Exception stackTrace) {
logger.log(severity, message, stackTrace);
}
}
EOF
echo "${LOGGERCLASS}" > "${PACKAGE}"/src/utils/"${PACKAGE}"Logger.java
}
function createFXMLData() {
read -d '' FXMLDATA << EOF
EOF
echo "${FXMLDATA}" > "${PACKAGE}"/com/"${COMPANYNAME,,}"/"${PACKAGE,,}"/resources/"${PACKAGE}".fxml
}

View File

@ -0,0 +1,47 @@
#!/bin/bash
function createScriptData() {
read -d '' COMPILESCRIPT << EOF
#!/bin/bash
# -Xlint:unchecked
function main() {
javac *.java utils/*.java
rm ../com/${COMPANYNAME,,}/${PACKAGE,,}/*.class
rm ../com/${COMPANYNAME,,}/${PACKAGE,,}/utils/*.class
mv *.class ../com/${COMPANYNAME,,}/${PACKAGE,,}/
mv utils/*.class ../com/${COMPANYNAME,,}/${PACKAGE,,}/utils/
}
main;
EOF
read -d '' BUILDJARSCRIPT << EOF
#!/bin/bash
function main() {
jar cvfm ${PACKAGE}.jar manifest.txt com/${COMPANYNAME,,}/${PACKAGE,,}/*.class \
com/${COMPANYNAME,,}/${PACKAGE,,}/utils/*.class \
com/${COMPANYNAME,,}/${PACKAGE,,}/resources
chmod +x ${PACKAGE}.jar
mv ${PACKAGE}.jar bin/
}
main;
EOF
echo "${COMPILESCRIPT}" > "${PACKAGE}"/src/unix_compile.sh
echo "${BUILDJARSCRIPT}" > "${PACKAGE}"/buildJar.sh
}
function createManifest() {
read -d '' MANIFESTDATA <<- EOF
Class-Path:
SplashScreen-Image: com/${COMPANYNAME,,}/${PACKAGE,,}/resources/${PACKAGE}Splash.jpg
Main-Class: com.${COMPANYNAME,,}.${PACKAGE,,}.${PACKAGE}
EOF
echo "${MANIFESTDATA}" > "${PACKAGE}"/manifest.txt
}

View File

@ -0,0 +1,62 @@
#!/bin/bash
. insertScriptData.sh
. insertBaseJavaData.sh
function main() {
clear;
echo "Name of package with proper Upercase convention...";
read -p "-> : " PACKAGE;
echo -e "\n\nName of your company or group to setup Jar structure...\n" \
"Usage Example: com/<companyORgroup>/${PACKAGE,,}" \
"Note: This will be made lowercase."
read -p "-> : " COMPANYNAME;
echo -e "\n\nMaking directories...";
sleep 1;
makeDirs "${PACKAGE}" "${COMPANYNAME}";
echo "Making source files...";
sleep 1;
makeSrcFiles "${PACKAGE}" "${COMPANYNAME}";
echo "Inserting script data to compile and build scripts...";
sleep 1;
createScriptData "${PACKAGE}" "${COMPANYNAME}";
echo "Creating basic Manifest file for Jar building...";
sleep 1;
createManifest "${PACKAGE}" "${COMPANYNAME}";
echo "Inserting basic Java data to ${PACKAGE} and its ${PACKAGE,,}Logger ...";
sleep 1;
createJavaData "${PACKAGE}" "${COMPANYNAME}";
echo -e "\t\t\nFinished!\n";
openOrExit "${PACKAGE}";
}
function makeDirs() {
mkdir -p "${PACKAGE}"/bin/resources/ "${PACKAGE}"/src/ "${PACKAGE}"/src/utils/ \
"${PACKAGE}"/com/"${COMPANYNAME,,}"/"${PACKAGE,,}"/resources \
"${PACKAGE}"/com/"${COMPANYNAME,,}"/"${PACKAGE,,}"/utils
}
function makeSrcFiles() {
touch "${PACKAGE}"/com/"${COMPANYNAME,,}"/"${PACKAGE,,}"/resources/"${PACKAGE}".fxml \
"${PACKAGE}"/com/"${COMPANYNAME,,}"/"${PACKAGE,,}"/resources/stylesheet.css \
"${PACKAGE}"/src/unix_compile.sh "${PACKAGE}"/buildJar.sh "${PACKAGE}"/manifest.txt \
"${PACKAGE}"/src/"${PACKAGE}".java "${PACKAGE}"/src/utils/"${PACKAGE}"Logger.java \
"${PACKAGE}"/src/Controller.java
# Make scripts runnable
chmod 744 "${PACKAGE}"/src/unix_compile.sh
chmod 744 "${PACKAGE}"/buildJar.sh
}
function openOrExit() {
echo -e "Open ${PACKAGE}/src/Controller.java\n"
read -p "-->(Yy/Nn): " ANS;
case "${ANS,,}" in
y ) atom "${PACKAGE}"/src/Controller.java & ;;
n ) exit ;;
* ) ;;
esac
}
main;