[Git][java-team/auto64fto32f][master] 15 commits: New upstream version 3.0.0+ds
Andrius Merkys (@merkys)
gitlab at salsa.debian.org
Mon Sep 12 14:36:02 BST 2022
Andrius Merkys pushed to branch master at Debian Java Maintainers / auto64fto32f
Commits:
293a1019 by Andrius Merkys at 2022-09-09T03:58:06-04:00
New upstream version 3.0.0+ds
- - - - -
60ded658 by Andrius Merkys at 2022-09-09T03:58:09-04:00
Update upstream source from tag 'upstream/3.0.0+ds'
Update to upstream version '3.0.0+ds'
with Debian dir ab0db67b1aa3f7138c5633f51b4b3302cbae3795
- - - - -
2c50a5c4 by Andrius Merkys at 2022-09-09T03:59:50-04:00
Package new upstream release.
- - - - -
a5776f76 by Andrius Merkys at 2022-09-09T04:20:33-04:00
Install the built JAR.
- - - - -
a16901e6 by Andrius Merkys at 2022-09-09T04:21:08-04:00
Do not build tests and javadoc.
- - - - -
b8edf9a4 by Andrius Merkys at 2022-09-09T07:11:05-04:00
New upstream version 2.1+ds
- - - - -
d8da7daa by Andrius Merkys at 2022-09-09T07:11:08-04:00
Update upstream source from tag 'upstream/2.1+ds'
Update to upstream version '2.1+ds'
with Debian dir be15ce4b4eb03c5af7d6fadf8e0adac1272db673
- - - - -
342fe68d by Andrius Merkys at 2022-09-09T07:11:38-04:00
Package v2.1.
- - - - -
9d445325 by Andrius Merkys at 2022-09-12T09:07:02-04:00
Simplify build.
- - - - -
aa07e05a by Andrius Merkys at 2022-09-12T09:08:39-04:00
Add ${java:Depends}.
- - - - -
97b5bab7 by Andrius Merkys at 2022-09-12T09:10:01-04:00
Remove unnecessary dependencies.
- - - - -
27ef2662 by Andrius Merkys at 2022-09-12T09:14:08-04:00
Bump debhelper-compat (no changes).
- - - - -
38f9c46d by Andrius Merkys at 2022-09-12T09:14:22-04:00
Remove debian/libauto64fto32f-java.poms.
- - - - -
d229eb9c by Andrius Merkys at 2022-09-12T09:17:24-04:00
Bump copyright dates.
- - - - -
104a5f0b by Andrius Merkys at 2022-09-12T09:17:40-04:00
Update debian/changelog.
- - - - -
19 changed files:
- + LICENSE-MIT
- README.MD
- build.gradle
- change.txt
- debian/changelog
- + debian/clean
- − debian/compat
- debian/control
- debian/copyright
- + debian/install
- − debian/libauto64fto32f-java.poms
- debian/rules
- examples/Example64to32App.java
- examples/dummy/DummyCode_F64.java
- + src/com/peterabeles/auto64fto32f/AugmentJavaFiles.java
- src/com/peterabeles/auto64fto32f/ConvertFile32From64.java
- + src/com/peterabeles/auto64fto32f/Language.java
- src/com/peterabeles/auto64fto32f/RecursiveConvert.java
- + test/com/peterabeles/auto64fto32f/TestAugmentJavaFiles.java
Changes:
=====================================
LICENSE-MIT
=====================================
@@ -0,0 +1,23 @@
+Copyright (c) 2018 Peter Abeles, <peter.abeles at gmail.com>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the Software
+without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to
+whom the Software is furnished to do so, subject to the
+following conditions:
+
+The above copyright notice and this permission notice shall
+be included in all copies or substantial portions of the
+Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
=====================================
README.MD
=====================================
@@ -23,7 +23,7 @@ Processing Steps:
White space is written to the output unmodified
3. Words are transformed by applying four separate sets of filters in the following order.
- * REGEX matching: If part of the word matches a regex that portion of the word is replaced with replacement text
+ * REGEX matching: If part of the word matches a regex that portion of the word is replaced with the replacement text
* Starts with matching: If the word begins with the specified text it is replaced with the replacement text.
* double replacement: An internally specified regex is used to detect doubles (e.g. 45.0 or 4.) and convert it into a float
* After REGEX matching: Another round of regex matching. Can be used to undo an earlier modification
@@ -76,7 +76,7 @@ Converted Code:
float foo = 1.6f*bar + (float)Math.exp(6) + (float)moo;
```
-The sequence ```/**/double``` is searched for an ignored, thus it will remain a double in the floating point code. ```/**/Math``` will not be typecasted because there is no space in front of Math. More on that Math issue later.
+The sequence ```/**/double``` is searched for and ignored, thus it will remain a double in the floating point code. ```/**/Math``` will not be typecasted because there is no space in front of Math. More on that Math issue later.
To avoid a compile time exception in the float code the variable 'moo' needs to be converted into a float. That is accomplished through a gratuitous (double) typecast.
@@ -97,6 +97,10 @@ double foo = 1.6*bar + Math.exp(6);
float foo = 1.6f*bar + (float)Math.exp(6);
```
+## License
+
+This software is released under multiple licenses; Unlicense and MIT License. You may choose one or all of these licenses when using this software. For specific details on Unlicense and MIT License look at the UNLICENSE and LICENSE-MIT files, respectively.
+
## Author
-This software is written by Peter Abeles and has been released as public domain software. See UNLICENSE
\ No newline at end of file
+This software is written by Peter Abeles
\ No newline at end of file
=====================================
build.gradle
=====================================
@@ -3,16 +3,16 @@ ext.libpath = file('./').absolutePath
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'java'
-apply plugin: 'osgi'
apply plugin: 'maven'
apply plugin: 'signing'
group = 'com.peterabeles'
-version = '1.4'
+version = '2.1'
-
-sourceCompatibility = 1.8
-targetCompatibility = 1.8
+java {
+ sourceCompatibility = JavaVersion.VERSION_11
+ targetCompatibility = JavaVersion.VERSION_11
+}
repositories {
mavenCentral()
@@ -38,13 +38,6 @@ javadoc {
}
}
-jar {
- manifest { // the manifest of the default jar is of type OsgiManifest
- instruction 'Bundle-Vendor', 'Peter Abeles'
- instruction 'Bundle-DocURL', 'http://peterabeles.com'
- }
-}
-
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
@@ -111,6 +104,10 @@ if( project.hasProperty('ossrhUsername') ) {
name 'Public Domain'
url 'http://unlicense.org/'
}
+ license {
+ name 'MIT'
+ url 'https://opensource.org/licenses/MIT'
+ }
}
developers {
@@ -126,13 +123,8 @@ if( project.hasProperty('ossrhUsername') ) {
}
}
-
-task testReport(type: TestReport) {
- destinationDir = file("$buildDir/reports/allTests")
- reportOn subprojects*.test
-}
-
-task wrapper(type: Wrapper) {
- gradleVersion = '4.3'
+wrapper {
+ distributionType = Wrapper.DistributionType.BIN
+ gradleVersion = '6.4.1'
}
=====================================
change.txt
=====================================
@@ -1,3 +1,22 @@
+------------------------------------------------------------------------------
+Version 2.1
+
+- Added markAsAutoGenerated flag
+ * If true the generated files will be marked as being auto generated using annotations
+ * Only used by Java for now
+ * Useful for static code tests that skip over auto generated files
+- Fixed issue with generics touching class name in Java
+
+------------------------------------------------------------------------------
+Version 2.0
+
+- 'interface' keyword is treated like 'class'
+- Start of multi language support
+
+------------------------------------------------------------------------------
+Version 1.4.1
+
+- Change to a dual license: Unlicense and MIT
------------------------------------------------------------------------------
Version 1.4
=====================================
debian/changelog
=====================================
@@ -1,3 +1,12 @@
+auto64fto32f (2.1+ds-1) unstable; urgency=medium
+
+ * Update debian/watch.
+ * New upstream version 2.1+ds
+ * Switch to javahelper.
+ * Bump debhelper-compat (no changes).
+
+ -- Andrius Merkys <merkys at debian.org> Mon, 12 Sep 2022 09:16:55 -0400
+
auto64fto32f (1.4+ds-2) unstable; urgency=medium
* d/copyright referred gversion-plugin, not auto64fto32f, fixed.
=====================================
debian/clean
=====================================
@@ -0,0 +1 @@
+auto64fto32f.jar
=====================================
debian/compat deleted
=====================================
@@ -1 +0,0 @@
-12
=====================================
debian/control
=====================================
@@ -5,9 +5,9 @@ Maintainer: Debian Java Maintainers <pkg-java-maintainers at lists.alioth.debian.or
Uploaders:
Andrius Merkys <merkys at debian.org>,
Build-Depends:
- debhelper (>= 12),
- gradle-debian-helper,
- maven-repo-helper,
+ debhelper-compat (= 13),
+ default-jdk,
+ javahelper,
Standards-Version: 4.3.0
Homepage: https://github.com/lessthanoptimal/Auto64Fto32F
Vcs-Browser: https://salsa.debian.org/java-team/auto64fto32f
@@ -16,6 +16,7 @@ Vcs-Git: https://salsa.debian.org/java-team/auto64fto32f.git
Package: libauto64fto32f-java
Architecture: all
Depends:
+ ${java:Depends},
${misc:Depends},
Description: minimalist library for converting double numerical Java code into float
This library is used to create applications that can convert code written with
=====================================
debian/copyright
=====================================
@@ -34,7 +34,7 @@ License: Unlicense
For more information, please refer to <http://unlicense.org/>
Files: debian/*
-Copyright: 2019 Andrius Merkys <merkys at debian.org>
+Copyright: 2019-2022, Andrius Merkys <merkys at debian.org>
License: MIT
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
=====================================
debian/install
=====================================
@@ -0,0 +1 @@
+auto64fto32f.jar usr/share/java
=====================================
debian/libauto64fto32f-java.poms deleted
=====================================
@@ -1,28 +0,0 @@
-# List of POM files for the package
-# Format of this file is:
-# <path to pom file> [option]*
-# where option can be:
-# --ignore: ignore this POM and its artifact if any
-# --ignore-pom: don't install the POM. To use on POM files that are created
-# temporarily for certain artifacts such as Javadoc jars. [mh_install, mh_installpoms]
-# --no-parent: remove the <parent> tag from the POM
-# --package=<package>: an alternative package to use when installing this POM
-# and its artifact
-# --has-package-version: to indicate that the original version of the POM is the same as the upstream part
-# of the version for the package.
-# --keep-elements=<elem1,elem2>: a list of XML elements to keep in the POM
-# during a clean operation with mh_cleanpom or mh_installpom
-# --artifact=<path>: path to the build artifact associated with this POM,
-# it will be installed when using the command mh_install. [mh_install]
-# --java-lib: install the jar into /usr/share/java to comply with Debian
-# packaging guidelines
-# --usj-name=<name>: name to use when installing the library in /usr/share/java
-# --usj-version=<version>: version to use when installing the library in /usr/share/java
-# --no-usj-versionless: don't install the versionless link in /usr/share/java
-# --dest-jar=<path>: the destination for the real jar.
-# It will be installed with mh_install. [mh_install]
-# --classifier=<classifier>: Optional, the classifier for the jar. Empty by default.
-# --site-xml=<location>: Optional, the location for site.xml if it needs to be installed.
-# Empty by default. [mh_install]
-#
-build/debian/auto64fto32f.pom --artifact=build/libs/auto64fto32f*.jar --java-lib
=====================================
debian/rules
=====================================
@@ -1,4 +1,9 @@
#!/usr/bin/make -f
+export JAVA_HOME = /usr/lib/jvm/default-java
+
%:
- dh $@ --with maven-repo-helper
+ dh $@ --with javahelper
+
+override_dh_auto_build:
+ jh_build --no-javadoc auto64fto32f.jar src
=====================================
examples/Example64to32App.java
=====================================
@@ -21,6 +21,9 @@ public class Example64to32App extends RecursiveConvert {
"examples"};
ConvertFile32From64 converter = new ConvertFile32From64(true);
+ // If your project imports javax.annotation.Generated then you will want all these files to be marked as
+ // generated for better code analysis
+// converter.markAsAutoGenerated = true;
// Add your own specialized strings
converter.replacePattern("MyConstants.EPS", "MyConstants.F_EPS");
=====================================
examples/dummy/DummyCode_F64.java
=====================================
@@ -7,7 +7,7 @@ package dummy;
*
* @author Peter Abeles
*/
-public class DummyCode_F64 {
+public class DummyCode_F64<Moo> {
public static double acuteAngle( double vx_a, double vy_a,
double vx_b, double vy_b ) {
double r_a = Math.sqrt( vx_a * vx_a + vy_a * vy_a );
@@ -16,6 +16,8 @@ public class DummyCode_F64 {
return Math.acos( ( vx_a * vx_b + vy_a * vy_b ) / ( r_a * r_b ) );
}
+ public void pointlessGeneric( Moo a ){}
+
public void encode(Sphere3D_F64 sphere, /**/double[] param) {
param[0] = sphere.x;
param[1] = sphere.y;
=====================================
src/com/peterabeles/auto64fto32f/AugmentJavaFiles.java
=====================================
@@ -0,0 +1,177 @@
+package com.peterabeles.auto64fto32f;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Scanner;
+
+/**
+ * Augments Java files to add code which did not originally exist. Currently this is only done to mark files as
+ * auto generated. Almost all other modifications are key word swaps.
+ *
+ * @author Peter Abeles
+ */
+public class AugmentJavaFiles {
+ /**
+ * Augments the input stream and returns a new stream with the augmentations
+ *
+ * @param stream Stream after being converted to 32
+ * @param originalFileName Original name of file used to generate it
+ * @return New stream after being augmented
+ */
+ public InputStream augment( InputStream stream , String originalFileName) throws IOException {
+ // Copy the entire stream into memory to make random access easier
+ String content = new Scanner(stream).useDelimiter("\\A").next();
+
+ StringBuilder builder = new StringBuilder(content.length());
+
+ String packageName = extractPackageName(content);
+ if( packageName.length() != 0 )
+ packageName += ".";
+
+ // Place the import statement just before the first "import"
+ int indexOfImport = findIndexWhereKeywordStartsLine(content,"import");
+ if( indexOfImport == -1 )
+ indexOfImport = findIndexAfterPackage(content); // no imports so stick it after package
+ builder.append(content,0,indexOfImport);
+ builder.append("import javax.annotation.Generated;\n");
+
+ int indexOfClass = findLineWhereClassIsDefined(content,indexOfImport);
+
+ // Make sure it already isn't marked as auto generated. We do this now because 99% of the time it will
+ // save time by avoiding searching the entire file for the word "generated"
+ if( content.substring(0, indexOfClass).contains("javax.annotation.Generated")) {
+ return new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
+ }
+
+ builder.append(content,indexOfImport,indexOfClass);
+ builder.append("@Generated(\""+packageName+originalFileName+"\")\n");
+ builder.append(content,indexOfClass,content.length());
+
+ return new ByteArrayInputStream(builder.toString().getBytes(StandardCharsets.UTF_8));
+ }
+
+ private String extractPackageName(String content) throws IOException {
+ int idx0 = findIndexWhereKeywordStartsLine(content,"package");
+ if( idx0 == -1 )
+ return "";
+ idx0 += "package".length()+1;
+ int idx1 = idx0;
+ while( idx1 < content.length() ) {
+ if( content.charAt(idx1) == ';') {
+ return content.substring(idx0,idx1);
+ }
+ idx1++;
+ }
+ throw new IOException("Couldn't find valid package name");
+ }
+
+ private int findIndexWhereKeywordStartsLine(String content, String keyword) throws IOException {
+ int loc = 0;
+ while( true ) {
+ loc = content.indexOf(keyword,loc);
+ if( loc == -1 )
+ return -1;
+ if( loc == 0 )
+ break;
+ // see if import starts the time
+ if(isNewLine(content.charAt(loc-1)) )
+ break;
+ loc += keyword.length();
+ }
+ return loc;
+ }
+
+ private int findIndexAfterPackage(String content) throws IOException {
+ int index = findIndexWhereKeywordStartsLine(content,"package");
+ if( index == -1 )
+ return 0;
+ boolean foundNewLine = false;
+ while( index < content.length() ) {
+ if( foundNewLine ) {
+ if( !isNewLine(content.charAt(index)) )
+ return index;
+ } else if( isNewLine(content.charAt(index))) {
+ foundNewLine = true;
+ }
+ index++;
+ }
+ return index;
+ }
+
+ private int findLineWhereClassIsDefined( String content, int startIndex ) throws IOException {
+ int searchClass = content.indexOf("class",startIndex);
+ int searchInterface = content.indexOf("interface",startIndex);
+
+ int nextSearch = -1;
+ while( true ) {
+ if( nextSearch == 1 ) {
+ searchClass = content.indexOf("class",searchClass+5);
+ } else if( nextSearch == 2 ) {
+ searchInterface = content.indexOf("interface", searchInterface + 9);
+ }
+ if( searchClass < 0 && searchInterface < 0 )
+ throw new IOException("Couldn't find valid 'class' or 'interface'");
+ String keyword;
+ int indexInContent;
+ if( searchInterface < 0 || (searchClass>=0 && searchClass<searchInterface)) {
+ keyword = "class";
+ indexInContent = searchClass;
+ nextSearch = 1;
+ } else {
+ keyword = "interface";
+ indexInContent = searchInterface;
+ nextSearch = 2;
+ }
+ String line = extractLine(content,indexInContent);
+ String[] words = line.split("\\s+");
+
+ // make sure 'class' is a word and assume that 'class' and the class name are on the same line
+ String className = null;
+ for (int i = 0; i < words.length-1; i++) {
+ if( !words[i].equals(keyword))
+ continue;
+ className = words[i+1];
+ break;
+ }
+ if( className == null ) {
+ continue;
+ }
+
+ int locOfKeyWord = line.indexOf(keyword);
+ int locOfSlash = line.indexOf("/");
+ int locOfStar = line.indexOf("*");
+
+ // make a bunch of simplifying assumptions about comments and what's legal in java...
+ if( locOfSlash != -1 && locOfSlash < locOfKeyWord )
+ continue;
+ if( locOfStar != -1 && locOfStar < locOfKeyWord ) // you could do /**/
+ continue;
+ return indexInContent - locOfKeyWord;
+ }
+ }
+
+ private static String extractLine( String content , int seedIndex ) {
+ int idx0 = Math.max(0,seedIndex-1);
+ while( idx0 > 0 ) {
+ if( isNewLine(content.charAt(idx0)) ) {
+ idx0 += 1;
+ break;
+ }
+ idx0--;
+ }
+ int idx1 = Math.min(content.length(),seedIndex+1);
+ while( idx1 < content.length() ) {
+ if( isNewLine(content.charAt(idx1)) ) {
+ break;
+ }
+ idx1++;
+ }
+ return content.substring(idx0,idx1);
+ }
+
+ private static boolean isNewLine( char c ) {
+ return c == '\n' || c == '\r';
+ }
+}
=====================================
src/com/peterabeles/auto64fto32f/ConvertFile32From64.java
=====================================
@@ -4,7 +4,6 @@ import java.io.*;
import java.util.ArrayList;
import java.util.List;
-
/**
* Converts a file written for 64bit numbers into 32bit numbers by replacing keywords.
*
@@ -22,24 +21,46 @@ public class ConvertFile32From64 {
List<Replacement> replacementsAfter = new ArrayList<>();
boolean skipFilterOnLine;
+ /**
+ * If true then the files will be marked as being auto generated code. These files are often skipped my code
+ * validation tools.
+ */
+ public boolean markAsAutoGenerated = false;
+ private Language language = Language.JAVA;
/**
* Constructor
* @param addDefaultReplacements If true all of the defaults replacement patterns are applied.
*/
- public ConvertFile32From64( boolean addDefaultReplacements ) {
+ public ConvertFile32From64( Language language, boolean addDefaultReplacements ) {
if( addDefaultReplacements ) {
+ if( language == Language.JAVA ) {
// replacePattern("/\\*\\*/double", "FIXED_DOUBLE");
- replacePattern("double", "float");
- replacePattern("Double", "Float");
- replacePattern("_F64", "_F32");
-
- replaceStartsWith("Math.", "(float)Math.");
- replaceStartsWith("-Math.", "(float)-Math.");
-
- replacePatternAfter("FIXED_DOUBLE", "/\\*\\*/double");
+ replacePattern("double", "float");
+ replacePattern("Double", "Float");
+ replacePattern("_F64", "_F32");
+
+ replaceStartsWith("Math.", "(float)Math.");
+ replaceStartsWith("-Math.", "(float)-Math.");
+
+ replacePatternAfter("FIXED_DOUBLE", "/\\*\\*/double");
+ } else if( language == Language.KOTLIN ) {
+ replacePattern("Double", "Float");
+ replacePattern("_F64", "_F32");
+ replacePatternAfter("FIXED_DOUBLE", "/\\*\\*/Double");
+ }
}
}
+ public ConvertFile32From64( boolean addDefaultReplacements ) {
+ this(Language.JAVA,addDefaultReplacements);
+ }
+
+ public static String fileNameNoExtension( File f , Language language ) {
+ int langLength = language.suffix().length()+1; // +1 for '.', e.g. ".java"
+ String fileName=f.getName();
+ return fileName.substring(0, fileName.length() - langLength);
+ }
+
/**
* Applies the specified keyword replacements to the input file and saves the results to the output file
* @param inputFile File that is to be transformed. Unmodified.
@@ -54,7 +75,7 @@ public class ConvertFile32From64 {
out = new PrintStream(outputFile);
int n;
- StringBuffer s = new StringBuffer(1024);
+ StringBuilder s = new StringBuilder(1024);
boolean prevChar = false;
State state = State.INITIALIZING;
@@ -101,7 +122,8 @@ public class ConvertFile32From64 {
case INITIALIZING:
if (totalTokens == 0 && token.startsWith("/*")) {
state = State.INSIDE_COPYRIGHT;
- } else if (!(insideBlockComments || insideLineComment) && token.compareTo("class") == 0) {
+ } else if (!(insideBlockComments || insideLineComment) &&
+ (token.compareTo("class") == 0 || token.compareTo("interface") == 0)) {
state = State.BEFORE_CLASS_NAME;
}
handleToken(token);
@@ -116,8 +138,11 @@ public class ConvertFile32From64 {
case BEFORE_CLASS_NAME: // for the class name to be the same as the output file
state = State.MAIN;
- String name = outputFile.getName();
- out.print(name.substring(0, name.length() - 5));
+ // In Java there could be Generics touching the class name E.g. class Foo<A>
+ // make sure we keep that extra info
+ String inputName = fileNameNoExtension(inputFile,language);
+ String outputName = fileNameNoExtension(outputFile,language);
+ out.print(outputName + token.substring(inputName.length()));
break;
case MAIN:
@@ -142,8 +167,6 @@ public class ConvertFile32From64 {
if (prevChar) {
handleToken(s.toString());
}
- } catch( IOException e ) {
- throw e;
} finally {
out.close();
in.close();
@@ -151,6 +174,13 @@ public class ConvertFile32From64 {
// are running out because the GC isn't running?
System.gc();
}
+
+ // See if it needs to do some additional modifications
+ // TODO speed up by never saving to disk the first time
+ if( language == Language.JAVA && markAsAutoGenerated ) {
+ in = new AugmentJavaFiles().augment(new FileInputStream(outputFile),fileNameNoExtension(inputFile,language));
+ in.transferTo(new FileOutputStream(outputFile));
+ }
}
public void scanForCustomization( File inputFile ) throws IOException {
@@ -163,7 +193,7 @@ public class ConvertFile32From64 {
if( !line.startsWith("//CUSTOM"))
continue;
- String words[] = line.substring(9,line.length()).split(" ");
+ String[] words = line.substring(9).split(" ");
if( words[0].equals("ignore")) {
customIgnore.add(words[1]);
}
@@ -254,6 +284,14 @@ public class ConvertFile32From64 {
}
}
+ public Language getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(Language language) {
+ this.language = language;
+ }
+
private static class Replacement {
public String pattern;
public String replacement;
=====================================
src/com/peterabeles/auto64fto32f/Language.java
=====================================
@@ -0,0 +1,22 @@
+package com.peterabeles.auto64fto32f;
+
+/**
+ * Specify which language is being converted
+ *
+ * @author Peter Abeles
+ */
+public enum Language {
+
+ JAVA("java"),
+ KOTLIN("kt");
+
+ private String suffix;
+
+ Language( String suffix ) {
+ this.suffix = suffix;
+ }
+
+ public String suffix() {
+ return this.suffix;
+ }
+}
=====================================
src/com/peterabeles/auto64fto32f/RecursiveConvert.java
=====================================
@@ -14,6 +14,7 @@ public class RecursiveConvert {
private String suffice64 = "_F64";
private String suffice32 = "_F32";
+ private Language language = Language.JAVA;
public RecursiveConvert(ConvertFile32From64 converter ) {
this.converter = converter;
@@ -39,6 +40,7 @@ public class RecursiveConvert {
} if( !outputDirectory.isDirectory() ) {
throw new IllegalArgumentException( "Output isn't a directory. "+outputDirectory.getPath() );
}
+ converter.setLanguage(language);
System.out.println( "---- Directory " + inputDirectory );
@@ -47,22 +49,27 @@ public class RecursiveConvert {
if( files == null )
return;
- int length64 = suffice64.length()+5;
+
+ String fileEnding64 = suffice64 + "." + language.suffix();
+ String fileEnding32 = suffice32 + "." + language.suffix();
+ int length64 = fileEnding64.length();
for( File f : files ) {
+ if( !f.isFile() )
+ continue;
String n = f.getName();
- if( n.endsWith( suffice64+".java" ) ) {
- n = n.substring(0, n.length() - length64) + suffice32+".java";
- try {
- System.out.println( "Generating " + n );
- converter.process(f,new File(outputDirectory,n));
- } catch( Exception e ) {
- System.out.println("\n\n\nCode generation failed!");
- e.printStackTrace();
- System.out.flush();
- System.err.flush();
- throw new RuntimeException( e );
- }
+ if( !n.endsWith(fileEnding64) )
+ continue;
+ n = n.substring(0, n.length() - length64) + fileEnding32;
+ try {
+ System.out.println( "Generating " + n );
+ converter.process(f,new File(outputDirectory,n));
+ } catch( Exception e ) {
+ System.out.println("\n\n\nCode generation failed!");
+ e.printStackTrace();
+ System.out.flush();
+ System.err.flush();
+ throw new RuntimeException( e );
}
}
@@ -72,4 +79,12 @@ public class RecursiveConvert {
}
}
}
+
+ public Language getLanguage() {
+ return language;
+ }
+
+ public void setLanguage(Language language) {
+ this.language = language;
+ }
}
=====================================
test/com/peterabeles/auto64fto32f/TestAugmentJavaFiles.java
=====================================
@@ -0,0 +1,101 @@
+package com.peterabeles.auto64fto32f;
+
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Scanner;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Peter Abeles
+ */
+public class TestAugmentJavaFiles {
+ @Test
+ public void standardClass() throws IOException {
+ String input = "package dummy;\n" +
+ "import foobar;\n" +
+ "/** Going to mention the word class here to mess things up */\n" +
+ "public class DummyCode_F64 {}\n";
+
+ String expected = "package dummy;\n" +
+ "import javax.annotation.Generated;\n" +
+ "import foobar;\n" +
+ "/** Going to mention the word class here to mess things up */\n" +
+ "@Generated(\"dummy.DummyCode_F64\")\n" +
+ "public class DummyCode_F64 {}\n";
+
+ var alg = new AugmentJavaFiles();
+ InputStream foundStream = alg.augment(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)),"DummyCode_F64");
+ String found = new Scanner(foundStream).useDelimiter("\\A").next();
+
+ assertEquals(expected,found);
+ }
+
+ @Test
+ public void standardInterface() throws IOException {
+ String input = "package dummy;\n" +
+ "import foobar;\n" +
+ "/** Going to mention the word class here to mess things up */\n" +
+ "public interface DummyCode_F64 {}\n";
+
+ String expected = "package dummy;\n" +
+ "import javax.annotation.Generated;\n" +
+ "import foobar;\n" +
+ "/** Going to mention the word class here to mess things up */\n" +
+ "@Generated(\"dummy.DummyCode_F64\")\n" +
+ "public interface DummyCode_F64 {}\n";
+
+ var alg = new AugmentJavaFiles();
+ InputStream foundStream = alg.augment(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)),"DummyCode_F64");
+ String found = new Scanner(foundStream).useDelimiter("\\A").next();
+
+ assertEquals(expected,found);
+ }
+
+ @Test
+ public void alreadyGenerated() throws IOException {
+ String input = "package dummy;\n" +
+ "import javax.annotation.Generated;\n" +
+ "import foobar;\n" +
+ "/** Going to mention the word class here to mess things up */\n" +
+ "@Generated(\"dummy.DummyCode_F64\")\n" +
+ "public class DummyCode_F64 {}\n";
+
+ var alg = new AugmentJavaFiles();
+ InputStream foundStream = alg.augment(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)),"DummyCode_F64");
+ String found = new Scanner(foundStream).useDelimiter("\\A").next();
+
+ assertEquals(input,found);
+ }
+
+ @Test
+ public void withoutImport() throws IOException {
+ String input = "package dummy;\n" +
+ "\n" +
+ "/**\n" +
+ " * Going to mention the word class here to mess things up\n" +
+ " */\n" +
+ "public class DummyCode_F64 {\n"+
+ "}\n";
+
+ String expected = "package dummy;\n" +
+ "\n" +
+ "import javax.annotation.Generated;\n" +
+ "/**\n" +
+ " * Going to mention the word class here to mess things up\n" +
+ " */\n" +
+ "@Generated(\"dummy.DummyCode_F64\")\n" +
+ "public class DummyCode_F64 {\n" +
+ "}\n";
+
+ var alg = new AugmentJavaFiles();
+ InputStream foundStream = alg.augment(new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)),"DummyCode_F64");
+ String found = new Scanner(foundStream).useDelimiter("\\A").next();
+
+ assertEquals(expected,found);
+ }
+}
View it on GitLab: https://salsa.debian.org/java-team/auto64fto32f/-/compare/37d55b8884bd3c3d33d3af252c218364f106a4fc...104a5f0b699c906d9a638cb4176e12c86c124170
--
View it on GitLab: https://salsa.debian.org/java-team/auto64fto32f/-/compare/37d55b8884bd3c3d33d3af252c218364f106a4fc...104a5f0b699c906d9a638cb4176e12c86c124170
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20220912/c51a1513/attachment.htm>
More information about the pkg-java-commits
mailing list