commit 138f8e20c12ac647e3efb39f1ee03e1e9c8251c8 Author: rattatwinko Date: Wed May 21 18:37:47 2025 +0200 initial pnoise commit + Main Class + Perlin Noise Module Currently only generates 2D , i think diff --git a/.gitea/workflows/gradle_build.yaml b/.gitea/workflows/gradle_build.yaml new file mode 100644 index 0000000..98d65a4 --- /dev/null +++ b/.gitea/workflows/gradle_build.yaml @@ -0,0 +1,60 @@ +name: Gradle Build + +on: + push: + branches: [ main, master, dev ] + pull_request: + branches: [ main, master ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + cache: 'gradle' + + - name: Grant execute permission for gradlew + run: | + find . -name gradlew -type f -exec chmod +x {} \; + + - name: Debug Info + run: | + echo "Current workspace directory: $GITHUB_WORKSPACE" + echo "Current directory: $(pwd)" + echo "Project structure:" + find . -type f -name "*.kt" | sort + find . -type f -name "build.gradle*" + if [ -f ./gradlew ]; then + ./gradlew --version + else + echo "No wrapper found, will use system gradle" + gradle --version + fi + + - name: Build pnoise (pnoise) + working-directory: . + run: | + echo "Building pnoise" + echo "Current directory: $(pwd)" + # Run Gradle build + ./gradlew build + + - name: Upload pnoise artifact + uses: actions/upload-artifact@v3 + with: + name: pnoise + path: | + ./build/libs/*.jar + ./app/build/libs/*.jar + ./build/distributions/*.zip + ./app/build/distributions/*.zip + if-no-files-found: warn diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..d624b8e --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("java") +} + +group = "org.pnoise" +version = "1.0-SNAPSHOT" + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(platform("org.junit:junit-bom:5.10.0")) + testImplementation("org.junit.jupiter:junit-jupiter") +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a3289ee --- /dev/null +++ b/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Universal build script for Maven and Gradle projects + +echo "Current directory: $(pwd)" + +# Check for Gradle or Gradle Wrapper + +echo "Building Gradle project using wrapper: pnoise" +cd "." +chmod +x ./gradlew +./gradlew build +cd - > /dev/null + +echo "Build complete. Build artifacts should be in their respective target/ or build/libs/ directories." diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..edf269c --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed May 21 18:31:42 CEST 2025 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/pommer.py b/pommer.py new file mode 100644 index 0000000..46fd98d --- /dev/null +++ b/pommer.py @@ -0,0 +1,585 @@ +#!/usr/bin/env python3 + +""" +POMMER.PY + +THIS IS PROPRIETARY SOFTWARE DO NOT DISTRIBUTE TO OUTSIDERS! + +This Python File is distributed with every Kotlin Plugin Repository! +If you find this to be confusing to use look at the Documentation in "rattatwinko/pommer" + +Run this Script with Python 3.11 ; 3.9 + +This works with Gradle and Maven ; other Branch is for reliablitiy ; this one is for "Support" with larger *commercial* Builds + +""" + +import os +import xml.etree.ElementTree as ET +import re +from pathlib import Path +import argparse +import glob +import json + + +def parse_pom_xml(pom_path): + """ + Parse a pom.xml file and extract relevant information + """ + try: + print(f"Parsing POM file: {pom_path}") + + # Register the default namespace + ET.register_namespace('', "http://maven.apache.org/POM/4.0.0") + + # Parse the XML file + tree = ET.parse(pom_path) + root = tree.getroot() + + # Define namespace for easier XPath queries + ns = {'mvn': "http://maven.apache.org/POM/4.0.0"} + + # Extract project info + artifact_id = root.find('./mvn:artifactId', ns).text + group_id = root.find('./mvn:groupId', ns).text if root.find('./mvn:groupId', ns) is not None else "unknown" + version = root.find('./mvn:version', ns).text if root.find('./mvn:version', ns) is not None else "unknown" + name = root.find('./mvn:name', ns).text if root.find('./mvn:name', ns) is not None else artifact_id + + # Extract Java version + java_version_elem = root.find('./mvn:properties/mvn:java.version', ns) + java_version = java_version_elem.text if java_version_elem is not None else "17" # Default to Java 17 if not specified + + # Extract packaging type (default to jar if not specified) + packaging = root.find('./mvn:packaging', ns) + packaging = packaging.text if packaging is not None else "jar" + + # Check if Kotlin is used + kotlin_version_elem = root.find('./mvn:properties/mvn:kotlin.version', ns) + kotlin_version = kotlin_version_elem.text if kotlin_version_elem is not None else None + + # Check for Kotlin plugin or dependency + kotlin_plugin = None + kotlin_dep = None + + # Check for Kotlin plugin + plugins = root.findall('.//mvn:plugin', ns) + for plugin in plugins: + plugin_group = plugin.find('./mvn:groupId', ns) + if plugin_group is not None and plugin_group.text == 'org.jetbrains.kotlin': + kotlin_plugin = plugin + break + + # Check for Kotlin dependency + deps = root.findall('.//mvn:dependency', ns) + for dep in deps: + dep_group = dep.find('./mvn:groupId', ns) + dep_artifact = dep.find('./mvn:artifactId', ns) + if (dep_group is not None and dep_group.text == 'org.jetbrains.kotlin' and + dep_artifact is not None and 'kotlin-stdlib' in dep_artifact.text): + kotlin_dep = dep + break + + # Determine if this is a Kotlin project + is_kotlin = kotlin_version is not None or kotlin_plugin is not None or kotlin_dep is not None + + # Check for source directories + source_dir = None + source_dirs = root.findall('.//mvn:sourceDirectory', ns) + if source_dirs: + source_dir = source_dirs[0].text + + # Check for default goal (to use the same command as IntelliJ) + default_goal = None + default_goal_elem = root.find('./mvn:build/mvn:defaultGoal', ns) + if default_goal_elem is not None: + default_goal = default_goal_elem.text + + return { + "artifact_id": artifact_id, + "group_id": group_id, + "version": version, + "name": name, + "java_version": java_version, + "packaging": packaging, + "is_kotlin": is_kotlin, + "kotlin_version": kotlin_version, + "source_dir": source_dir, + "default_goal": default_goal, + "pom_path": pom_path, + "build_system": "maven" + } + except Exception as e: + print(f"Error parsing {pom_path}: {e}") + return None + + +def parse_gradle_file(gradle_path): + """ + Parse a build.gradle or build.gradle.kts file and extract relevant information + """ + try: + print(f"Parsing Gradle file: {gradle_path}") + + # Read the file content + with open(gradle_path, 'r') as f: + content = f.read() + + # Determine if it's a Kotlin DSL file + is_kotlin_dsl = gradle_path.endswith('.kts') + + # Extract group, version and project name + group_match = re.search(r'group\s*=\s*[\'"]([^\'"]+)[\'"]', content) + group_id = group_match.group(1) if group_match else "unknown" + + version_match = re.search(r'version\s*=\s*[\'"]([^\'"]+)[\'"]', content) + version = version_match.group(1) if version_match else "unknown" + + # Check settings.gradle for project name + settings_path = os.path.join(os.path.dirname(gradle_path), "settings.gradle") + settings_path_kts = os.path.join(os.path.dirname(gradle_path), "settings.gradle.kts") + + artifact_id = "unknown" + name = "unknown" + + if os.path.exists(settings_path): + with open(settings_path, 'r') as f: + settings_content = f.read() + root_project_match = re.search(r'rootProject\.name\s*=\s*[\'"]([^\'"]+)[\'"]', settings_content) + if root_project_match: + artifact_id = root_project_match.group(1) + name = artifact_id + elif os.path.exists(settings_path_kts): + with open(settings_path_kts, 'r') as f: + settings_content = f.read() + root_project_match = re.search(r'rootProject\.name\s*=\s*[\'"]([^\'"]+)[\'"]', settings_content) + if root_project_match: + artifact_id = root_project_match.group(1) + name = artifact_id + + # If no name found in settings.gradle, use directory name + if artifact_id == "unknown": + artifact_id = os.path.basename(os.path.dirname(gradle_path)) + name = artifact_id + + # Check for Java version + java_version = "17" # Default to Java 17 + java_version_match = re.search(r'sourceCompatibility\s*=\s*[\'"]*JavaVersion\.VERSION_(\d+)[\'"]*', content) + if java_version_match: + java_version = java_version_match.group(1) + else: + # Alternative pattern: sourceCompatibility = '11' + alt_java_match = re.search(r'sourceCompatibility\s*=\s*[\'"](\d+)[\'"]', content) + if alt_java_match: + java_version = alt_java_match.group(1) + else: + # Look for toolchain configuration + toolchain_match = re.search(r'toolchain\s*{[^}]*languageVersion\s*=\s*JavaLanguageVersion\s*\.\s*of\s*\(\s*(\d+)\s*\)', content, re.DOTALL) + if toolchain_match: + java_version = toolchain_match.group(1) + + # Check if Kotlin is used + kotlin_plugin_match = re.search(r'(id\s*\(\s*[\'"]kotlin[\'"])|(id\s*[\'"]org\.jetbrains\.kotlin)', content) + kotlin_version_match = re.search(r'kotlin\s*version\s*[\'"]([^\'"]+)[\'"]', content) + is_kotlin = bool(kotlin_plugin_match) or bool(kotlin_version_match) or is_kotlin_dsl + + kotlin_version = kotlin_version_match.group(1) if kotlin_version_match else None + + # Check for application plugin + is_application = bool(re.search(r'id\s*\(\s*[\'"]application[\'"]', content)) + + return { + "artifact_id": artifact_id, + "group_id": group_id, + "version": version, + "name": name, + "java_version": java_version, + "packaging": "jar" if not is_application else "application", + "is_kotlin": is_kotlin, + "kotlin_version": kotlin_version, + "source_dir": None, # Gradle uses conventional source dirs + "default_goal": None, # Gradle doesn't have default goals like Maven + "gradle_path": gradle_path, + "is_kotlin_dsl": is_kotlin_dsl, + "build_system": "gradle" + } + except Exception as e: + print(f"Error parsing {gradle_path}: {e}") + return None + + +def generate_maven_workflow(pom_infos): + """ + Generate a Gitea workflow YAML file for Maven projects + """ + if not pom_infos: + print("No valid Maven POM files found") + return None + + # Get the highest Java version required + java_version = max([info["java_version"] for info in pom_infos]) + + # Check if any project uses Kotlin + uses_kotlin = any(info["is_kotlin"] for info in pom_infos) + + # Kotlin version (if any) + kotlin_version = None + for info in pom_infos: + if info["kotlin_version"]: + kotlin_version = info["kotlin_version"] + break + + # Construct the workflow content + workflow_content = f"""name: Maven Build + +on: + push: + branches: [ main, master, dev ] + pull_request: + branches: [ main, master ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK {java_version} + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '{java_version}' + cache: 'maven' + + - name: Install Maven + run: | + if ! command -v mvn &> /dev/null; then + echo "Maven not found, installing..." + sudo apt-get update + sudo apt-get install -y maven + fi + mvn --version + + - name: Debug Info + run: | + echo "Current workspace directory: $GITHUB_WORKSPACE" + echo "Current directory: $(pwd)" + echo "Project structure:" + find . -type f -name "*.kt" | sort + find . -type f -name "pom.xml" + echo "Maven version: $(mvn --version)" +""" + + # Add individual build steps for each POM + for i, info in enumerate(pom_infos): + # Determine the Maven command to use (same as the default goal if specified) + maven_command = "clean package" + if info["default_goal"]: + maven_command = info["default_goal"] + + relative_pom_path = info["pom_path"] + + workflow_content += f""" + - name: Build {info["name"]} ({info["artifact_id"]}) + run: | + echo "Building {info["artifact_id"]}" + echo "Current directory: $(pwd)" + # Run Maven build directly using the POM file path + mvn -B {maven_command} -f "{relative_pom_path}" -Dmaven.compiler.failOnError=true +""" + + # Add artifact upload step + workflow_content += f""" + - name: Upload {info["artifact_id"]} artifact + uses: actions/upload-artifact@v3 + with: + name: {info["artifact_id"]} + path: | + {os.path.dirname(relative_pom_path)}/target/{info['artifact_id']}-*.jar + {os.path.dirname(relative_pom_path)}/target/*.jar + if-no-files-found: warn +""" + + return workflow_content + + +def generate_gradle_workflow(gradle_infos): + """ + Generate a Gitea workflow YAML file for Gradle projects + """ + if not gradle_infos: + print("No valid Gradle files found") + return None + + # Get the highest Java version required + java_version = max([info["java_version"] for info in gradle_infos]) + + # Check if any project uses Kotlin + uses_kotlin = any(info["is_kotlin"] for info in gradle_infos) + + # Kotlin version (if any) + kotlin_version = None + for info in gradle_infos: + if info["kotlin_version"]: + kotlin_version = info["kotlin_version"] + break + + # Construct the workflow content + workflow_content = f"""name: Gradle Build + +on: + push: + branches: [ main, master, dev ] + pull_request: + branches: [ main, master ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK {java_version} + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '{java_version}' + cache: 'gradle' + + - name: Grant execute permission for gradlew + run: | + find . -name gradlew -type f -exec chmod +x {{}} \; + + - name: Debug Info + run: | + echo "Current workspace directory: $GITHUB_WORKSPACE" + echo "Current directory: $(pwd)" + echo "Project structure:" + find . -type f -name "*.kt" | sort + find . -type f -name "build.gradle*" + if [ -f ./gradlew ]; then + ./gradlew --version + else + echo "No wrapper found, will use system gradle" + gradle --version + fi +""" + + # Add individual build steps for each Gradle project + for i, info in enumerate(gradle_infos): + project_dir = os.path.dirname(info["gradle_path"]) + has_wrapper = os.path.exists(os.path.join(project_dir, "gradlew")) + gradle_command = f"{os.path.join(project_dir, 'gradlew')}" if has_wrapper else "gradle" + + workflow_content += f""" + - name: Build {info["name"]} ({info["artifact_id"]}) + working-directory: {project_dir} + run: | + echo "Building {info["artifact_id"]}" + echo "Current directory: $(pwd)" + # Run Gradle build + {"./gradlew" if has_wrapper else "gradle"} build +""" + + # Add artifact upload step + workflow_content += f""" + - name: Upload {info["artifact_id"]} artifact + uses: actions/upload-artifact@v3 + with: + name: {info["artifact_id"]} + path: | + {project_dir}/build/libs/*.jar + {project_dir}/app/build/libs/*.jar + {project_dir}/build/distributions/*.zip + {project_dir}/app/build/distributions/*.zip + if-no-files-found: warn +""" + + return workflow_content + + +def find_pom_files(base_dir="."): + """Find all pom.xml files in the given directory and subdirectories""" + return glob.glob(f"{base_dir}/**/pom.xml", recursive=True) + + +def find_gradle_files(base_dir="."): + """Find all build.gradle and build.gradle.kts files in the given directory and subdirectories""" + gradle_files = glob.glob(f"{base_dir}/**/build.gradle", recursive=True) + kotlin_gradle_files = glob.glob(f"{base_dir}/**/build.gradle.kts", recursive=True) + return gradle_files + kotlin_gradle_files + + +def generate_build_script(project_infos): + """Generate a universal build script for either Maven or Gradle projects""" + + maven_projects = [p for p in project_infos if p["build_system"] == "maven"] + gradle_projects = [p for p in project_infos if p["build_system"] == "gradle"] + + script = """#!/bin/bash +# Universal build script for Maven and Gradle projects + +echo "Current directory: $(pwd)" +""" + + if maven_projects: + script += """ +# Check if Maven is installed +if ! command -v mvn &> /dev/null; then + echo "Maven not found, installing..." + sudo apt-get update + sudo apt-get install -y maven +fi + +echo "Maven version: $(mvn --version)" +""" + + for project in maven_projects: + script += f""" +echo "Building Maven project: {project['name']}" +mvn clean package -f "{project['pom_path']}" +""" + + if gradle_projects: + script += """ +# Check for Gradle or Gradle Wrapper +""" + for project in gradle_projects: + project_dir = os.path.dirname(project["gradle_path"]) + has_wrapper = os.path.exists(os.path.join(project_dir, "gradlew")) + + if has_wrapper: + script += f""" +echo "Building Gradle project using wrapper: {project['name']}" +cd "{project_dir}" +chmod +x ./gradlew +./gradlew build +cd - > /dev/null +""" + else: + script += f""" +echo "Building Gradle project using system Gradle: {project['name']}" +# Install Gradle if not available +if ! command -v gradle &> /dev/null; then + echo "Gradle not found, installing..." + sudo apt-get update + sudo apt-get install -y gradle +fi +cd "{project_dir}" +gradle build +cd - > /dev/null +""" + + script += """ +echo "Build complete. Build artifacts should be in their respective target/ or build/libs/ directories." +""" + return script + + +def main(): + parser = argparse.ArgumentParser(description='Generate Gitea workflow for Maven/Gradle/Kotlin projects') + parser.add_argument('--dir', '-d', default='.', help='Base directory to search for project files') + parser.add_argument('--specific-pom', '-p', help='Path to a specific pom.xml file to process') + parser.add_argument('--specific-gradle', '-g', help='Path to a specific build.gradle file to process') + parser.add_argument('--output-json', '-j', action='store_true', help='Output project info as JSON as well') + args = parser.parse_args() + + # Find project files + pom_files = [] + gradle_files = [] + + if args.specific_pom: + pom_files = [args.specific_pom] + else: + pom_files = find_pom_files(args.dir) + + if args.specific_gradle: + gradle_files = [args.specific_gradle] + else: + gradle_files = find_gradle_files(args.dir) + + if not pom_files and not gradle_files: + print(f"No pom.xml or build.gradle files found in {args.dir}") + return + + print(f"Found {len(pom_files)} pom.xml files and {len(gradle_files)} Gradle files") + + # Parse all project files + project_infos = [] + + # Parse Maven files + for pom_file in pom_files: + info = parse_pom_xml(pom_file) + if info: + project_infos.append(info) + + # Parse Gradle files + for gradle_file in gradle_files: + info = parse_gradle_file(gradle_file) + if info: + project_infos.append(info) + + if not project_infos: + print("No valid project files could be parsed") + return + + # Count by build system + maven_count = sum(1 for p in project_infos if p["build_system"] == "maven") + gradle_count = sum(1 for p in project_infos if p["build_system"] == "gradle") + + # Create the .gitea/workflows directory if it doesn't exist + workflow_dir = Path(".gitea/workflows") + workflow_dir.mkdir(parents=True, exist_ok=True) + + # Generate and write workflow files for each build system + if maven_count > 0: + maven_infos = [p for p in project_infos if p["build_system"] == "maven"] + maven_workflow = generate_maven_workflow(maven_infos) + if maven_workflow: + maven_workflow_file = workflow_dir / "maven_build.yaml" + with open(maven_workflow_file, "w") as f: + f.write(maven_workflow) + print(f"Gitea Maven workflow generated at: {maven_workflow_file}") + + if gradle_count > 0: + gradle_infos = [p for p in project_infos if p["build_system"] == "gradle"] + gradle_workflow = generate_gradle_workflow(gradle_infos) + if gradle_workflow: + gradle_workflow_file = workflow_dir / "gradle_build.yaml" + with open(gradle_workflow_file, "w") as f: + f.write(gradle_workflow) + print(f"Gitea Gradle workflow generated at: {gradle_workflow_file}") + + # Generate a universal build script + build_script = generate_build_script(project_infos) + with open("build.sh", "w") as f: + f.write(build_script) + os.chmod("build.sh", 0o755) + print(f"Universal build script generated at: build.sh") + + # Print summary of detected projects + print("\nDetected projects:") + for info in project_infos: + kotlin_info = "with Kotlin" if info["is_kotlin"] else "Java only" + if info["build_system"] == "maven": + build_command = info["default_goal"] if info["default_goal"] else "clean package" + print(f"- {info['name']} ({info['artifact_id']}): Maven, {kotlin_info}, Java {info['java_version']}, build: {build_command}") + else: + dsl_info = "Kotlin DSL" if info.get("is_kotlin_dsl") else "Groovy DSL" + print(f"- {info['name']} ({info['artifact_id']}): Gradle ({dsl_info}), {kotlin_info}, Java {info['java_version']}") + + # Export as JSON if requested + if args.output_json: + with open("project_info.json", "w") as f: + json.dump(project_infos, f, indent=2) + print(f"Project information exported to project_info.json") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..5a52674 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "pnoise" \ No newline at end of file diff --git a/src/main/java/org/pnoise/Main.java b/src/main/java/org/pnoise/Main.java new file mode 100644 index 0000000..6e4828b --- /dev/null +++ b/src/main/java/org/pnoise/Main.java @@ -0,0 +1,89 @@ +package org.pnoise; + +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; + +public class Main { + + public static void main(String[] args) { + NoiseGenerator noiseGen = new NoiseGenerator(); + SwingUtilities.invokeLater(() -> new NoiseAnimationFrame(noiseGen).startAnimation()); + } +} + +class NoiseAnimationFrame extends JFrame { + + private final NoiseGenerator noiseGen; + private final NoisePanel noisePanel; + + private double z = 0; // z-coordinate for 3D noise + private final double zSpeed = 0.5; // speed to move through z-axis + + public NoiseAnimationFrame(NoiseGenerator noiseGen) { + super("3D Noise Animation"); + + this.noiseGen = noiseGen; + this.noisePanel = new NoisePanel(); + + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + add(noisePanel); + setSize(512, 512); // Start with bigger window + setLocationRelativeTo(null); + setVisible(true); + } + + public void startAnimation() { + Timer timer = new Timer(33, e -> { + z += zSpeed; + noisePanel.updateNoise(z); + }); + timer.start(); + } + + class NoisePanel extends JPanel { + + private final int noiseWidth = 256; + private final int noiseHeight = 256; + private BufferedImage noiseImage; + + public NoisePanel() { + noiseImage = new BufferedImage(noiseWidth, noiseHeight, BufferedImage.TYPE_INT_RGB); + } + + public void updateNoise(double z) { + for (int x = 0; x < noiseWidth; x++) { + for (int y = 0; y < noiseHeight; y++) { + double val = noiseGen.noise(x * 0.1, y * 0.1, z); + int gray = (int) (val * 255); + gray = Math.min(255, Math.max(0, gray)); + int rgb = new Color(gray, gray, gray).getRGB(); + noiseImage.setRGB(x, y, rgb); + } + } + repaint(); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + // Draw noiseImage scaled to fill entire panel + Graphics2D g2d = (Graphics2D) g.create(); + + // Use rendering hints for better scaling quality + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, + RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + int panelWidth = getWidth(); + int panelHeight = getHeight(); + + g2d.drawImage(noiseImage, 0, 0, panelWidth, panelHeight, null); + g2d.dispose(); + } + } +} diff --git a/src/main/java/org/pnoise/NoiseGenerator.java b/src/main/java/org/pnoise/NoiseGenerator.java new file mode 100644 index 0000000..829998a --- /dev/null +++ b/src/main/java/org/pnoise/NoiseGenerator.java @@ -0,0 +1,160 @@ +package org.pnoise; +import java.util.Random; + +public class NoiseGenerator { + private double seed; + private long default_size; + private int[] p; + private int[] permutation; + + public NoiseGenerator(double seed) { + this.seed = seed; + init(); + } + + public NoiseGenerator() { + this.seed = new Random().nextGaussian() * 255; + init(); + } + + private void init() { + // Initialize the permutation array. + this.p = new int[512]; + this.permutation = new int[] { 151, 160, 137, 91, 90, 15, 131, 13, 201, + 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, + 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, + 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, + 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, + 165, 71, 134, 139, 48, 27, 166, 77, 146, 158, 231, 83, 111, + 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, + 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, + 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, + 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, + 124, 123, 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, + 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, 223, 183, 170, + 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, + 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, + 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, + 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, + 249, 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, + 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, + 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, + 215, 61, 156, 180 }; + this.default_size = 35; + + // Populate it + for (int i = 0; i < 256; i++) { + p[256 + i] = p[i] = permutation[i]; + } + + } + + public void setSeed(double seed) { + this.seed = seed; + } + + public double getSeed() { + return this.seed; + } + + public double noise(double x, double y, double z, int size) { + double value = 0.0; + double initialSize = size; + + while (size >= 1) { + value += smoothNoise((x / size), (y / size), (z / size)) * size; + size /= 2.0; + } + + return value / initialSize; + } + + public double noise(double x, double y, double z) { + double value = 0.0; + double size = default_size; + double initialSize = size; + + while (size >= 1) { + value += smoothNoise((x / size), (y / size), (z / size)) * size; + size /= 2.0; + } + + return value / initialSize; + } + + public double noise(double x, double y) { + double value = 0.0; + double size = default_size; + double initialSize = size; + + while (size >= 1) { + value += smoothNoise((x / size), (y / size), (0f / size)) * size; + size /= 2.0; + } + + return value / initialSize; + } + + public double noise(double x) { + double value = 0.0; + double size = default_size; + double initialSize = size; + + while (size >= 1) { + value += smoothNoise((x / size), (0f / size), (0f / size)) * size; + size /= 2.0; + } + + return value / initialSize; + } + + public double smoothNoise(double x, double y, double z) { + // Offset each coordinate by the seed value + x += this.seed; + y += this.seed; + x += this.seed; + + int X = (int) Math.floor(x) & 255; // FIND UNIT CUBE THAT + int Y = (int) Math.floor(y) & 255; // CONTAINS POINT. + int Z = (int) Math.floor(z) & 255; + + x -= Math.floor(x); // FIND RELATIVE X,Y,Z + y -= Math.floor(y); // OF POINT IN CUBE. + z -= Math.floor(z); + + double u = fade(x); // COMPUTE FADE CURVES + double v = fade(y); // FOR EACH OF X,Y,Z. + double w = fade(z); + + int A = p[X] + Y; + int AA = p[A] + Z; + int AB = p[A + 1] + Z; // HASH COORDINATES OF + int B = p[X + 1] + Y; + int BA = p[B] + Z; + int BB = p[B + 1] + Z; // THE 8 CUBE CORNERS, + + return lerp(w, lerp(v, lerp(u, grad(p[AA], x, y, z ), // AND ADD + grad(p[BA], x - 1, y, z )), // BLENDED + lerp(u, grad(p[AB], x, y - 1, z ), // RESULTS + grad(p[BB], x - 1, y - 1, z ))),// FROM 8 + lerp(v, lerp(u, grad(p[AA + 1], x, y, z - 1 ), // CORNERS + grad(p[BA + 1], x - 1, y, z - 1 )), // OF CUBE + lerp(u, grad(p[AB + 1], x, y - 1, z - 1 ), + grad(p[BB + 1], x - 1, y - 1, z - 1 )))); + } + + private double fade(double t) { + return t * t * t * (t * (t * 6 - 15) + 10); + } + + private double lerp(double t, double a, double b) { + return a + t * (b - a); + } + + private double grad(int hash, double x, double y, double z) { + int h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE + double u = h < 8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. + v = h < 4 ? y : h == 12 || h == 14 ? x : z; + return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); + } +} \ No newline at end of file