├── .github └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── ROTATING-GPG-KEY.md ├── UPGRADING-XTEXT.md ├── build.sh ├── deploy └── settings.xml ├── examples ├── pom.xml └── zip-file-format │ ├── pom.xml │ └── src │ ├── main │ └── structs │ │ └── zip.structs │ └── test │ ├── java │ └── examples │ │ └── zip │ │ ├── ZipFileReadingTest.java │ │ └── ZipFileWritingTest.java │ └── resources │ ├── README.md │ ├── example.zip │ └── zip-content │ ├── file1.txt │ └── file2.txt ├── org.structs4java.parent ├── org.structs4java.feature │ ├── .project │ ├── build.properties │ ├── feature.xml │ └── pom.xml ├── org.structs4java.ide │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ └── org.eclipse.xtend.core.Xtend.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── bin │ │ └── build.properties │ ├── build.properties │ ├── pom.xml │ └── src │ │ └── org │ │ └── structs4java │ │ └── ide │ │ ├── Structs4JavaDslIdeModule.xtend │ │ └── Structs4JavaDslIdeSetup.xtend ├── org.structs4java.target │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ └── org.eclipse.m2e.core.prefs │ ├── org.structs4java.target.target │ └── pom.xml ├── org.structs4java.tests │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ └── org.eclipse.xtend.core.Xtend.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── bin │ │ └── build.properties │ ├── build.properties │ ├── pom.xml │ └── src │ │ └── org │ │ └── structs4java │ │ └── tests │ │ ├── DefaultValuesParsingTest.xtend │ │ └── Structs4JavaDslParsingTest.xtend ├── org.structs4java.ui.tests │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ └── org.eclipse.xtend.core.Xtend.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── bin │ │ └── build.properties │ ├── build.properties │ └── pom.xml ├── org.structs4java.ui │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ └── org.eclipse.xtend.core.Xtend.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── bin │ │ └── build.properties │ ├── build.properties │ ├── plugin.xml │ ├── plugin.xml_gen │ ├── pom.xml │ └── src │ │ └── org │ │ └── structs4java │ │ └── ui │ │ ├── CustomNatureAddingEditorCallback.java │ │ ├── Structs4JavaDslUiModule.xtend │ │ ├── contentassist │ │ └── Structs4JavaDslProposalProvider.xtend │ │ ├── labeling │ │ ├── Structs4JavaDslDescriptionLabelProvider.xtend │ │ └── Structs4JavaDslLabelProvider.xtend │ │ ├── outline │ │ └── Structs4JavaDslOutlineTreeProvider.xtend │ │ └── quickfix │ │ └── Structs4JavaDslQuickfixProvider.xtend ├── org.structs4java │ ├── .classpath │ ├── .project │ ├── .settings │ │ ├── org.eclipse.core.resources.prefs │ │ ├── org.eclipse.jdt.core.prefs │ │ ├── org.eclipse.m2e.core.prefs │ │ └── org.eclipse.xtend.core.Xtend.prefs │ ├── META-INF │ │ └── MANIFEST.MF │ ├── build.properties │ ├── plugin.xml │ ├── plugin.xml_gen │ ├── pom.xml │ └── src │ │ └── org │ │ └── structs4java │ │ ├── GenerateStructs4JavaDsl.mwe2 │ │ ├── Structs4JavaDsl.xtext │ │ ├── Structs4JavaDslRuntimeModule.xtend │ │ ├── Structs4JavaDslStandaloneSetup.xtend │ │ ├── Structs4JavaQualifiedNameProvider.java │ │ ├── converter │ │ └── Structs4JavaDslValueConverter.java │ │ ├── formatting2 │ │ └── Structs4JavaDslFormatter.xtend │ │ ├── generator │ │ ├── EnumGenerator.xtend │ │ ├── StructGenerator.xtend │ │ └── Structs4JavaDslGenerator.xtend │ │ ├── jvmmodel │ │ └── Structs4JavaDslJvmModelInferrer.xtend │ │ ├── scoping │ │ ├── MyImportedNamespaceAwareLocalScopeProvider.java │ │ └── Structs4JavaDslScopeProvider.xtend │ │ └── validation │ │ └── Structs4JavaDslValidator.xtend └── pom.xml ├── pom.xml ├── structs4java-core ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── structs4java │ ├── MavenStructs4JavaDslRuntimeModule.java │ ├── MavenStructs4JavaDslStandaloneSetupGenerated.java │ └── StructsBatchCompiler.java ├── structs4java-gradle-plugin ├── .gitattributes ├── .gitignore ├── gradle.properties ├── gradle │ ├── libs.versions.toml │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── plugin │ ├── build.gradle.kts │ └── src │ │ ├── functionalTest │ │ └── java │ │ │ └── org │ │ │ └── structs4java │ │ │ └── Structs4javaGradlePluginFunctionalTest.java │ │ ├── main │ │ └── java │ │ │ └── org │ │ │ └── structs4java │ │ │ ├── CompileStructsTask.java │ │ │ └── Structs4javaGradlePlugin.java │ │ └── test │ │ └── java │ │ └── org │ │ └── structs4java │ │ └── Structs4javaGradlePluginTest.java └── settings.gradle.kts ├── structs4java-maven-plugin-test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── structs4java │ │ │ └── example │ │ │ └── tests │ │ │ ├── InterfaceA.java │ │ │ └── InterfaceB.java │ └── structs │ │ ├── Bitfields.structs │ │ ├── CopyConstructorCases.structs │ │ ├── EndianessTest.structs │ │ ├── EnumWithLargeNumbers.structs │ │ ├── Example1.structs │ │ ├── Example2.structs │ │ ├── Example3.structs │ │ ├── Example4.structs │ │ ├── FixSizedStringWithCustomFiller.structs │ │ ├── GreedyTest.structs │ │ ├── ImplicitImportOfSameNamespace.structs │ │ ├── NotNullTerminatedVarSizeString.structs │ │ ├── PadUsingCustomByte.structs │ │ ├── PaddingTest.structs │ │ ├── SizeOfArray.structs │ │ ├── StructWith64BitSizeType.structs │ │ ├── StructWithInterfaces.structs │ │ ├── WriteStringBug.structs │ │ ├── bugs.structs │ │ ├── constants.structs │ │ ├── default-values.structs │ │ ├── default_package.structs │ │ └── null-safety.structs │ └── test │ └── java │ └── org │ └── structs4java │ └── example │ └── tests │ ├── AbstractTest.java │ ├── ConstantTest.java │ ├── DefaultValueTest.java │ ├── NullSafetyTest.java │ └── RegressionTest.java ├── structs4java-maven-plugin ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── structs4java │ ├── AbstractCompileMojo.java │ ├── CompileMojo.java │ ├── MavenLog4JConfigurator.java │ └── TestCompileMojo.java └── structs4java-with-dependencies └── pom.xml /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI on master 2 | 3 | on: 4 | pull_request: 5 | branches: [ "master" ] 6 | push: 7 | branches: [ "master" ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v3 17 | with: 18 | fetch-depth: 0 # required for github-action-get-previous-tag 19 | 20 | - name: Set up JDK 17 21 | uses: actions/setup-java@v4 22 | with: 23 | java-version: '17' 24 | distribution: 'temurin' 25 | 26 | - name: Set up Maven 27 | uses: stCarolas/setup-maven@v5 28 | with: 29 | maven-version: 3.9.6 30 | 31 | - name: Setup Gradle 32 | uses: gradle/actions/setup-gradle@v3 33 | 34 | - name: Build with Maven 35 | uses: GabrielBB/xvfb-action@v1 36 | with: 37 | run: mvn clean install -Dmaven.repo.local=./.m2 -Declipse.p2.mirrors=false 38 | 39 | - name: Build with Gradle 40 | run: cd ./structs4java-gradle-plugin && ./gradlew build 41 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v3 15 | 16 | - name: Set up JDK 17 17 | uses: actions/setup-java@v4 18 | with: 19 | java-version: '17' 20 | distribution: 'temurin' 21 | 22 | - name: Set up Maven 23 | uses: stCarolas/setup-maven@v5 24 | with: 25 | maven-version: 3.9.6 26 | 27 | - name: Setup Gradle 28 | uses: gradle/actions/setup-gradle@v3 29 | 30 | - name: Set version in Maven and Tycho 31 | run: | 32 | mvn -f $(pwd)/org.structs4java.parent/pom.xml org.eclipse.tycho:tycho-versions-plugin:1.0.0:set-version -DnewVersion=${{ github.event.release.tag_name }} -Dmaven.repo.local=./.m2 33 | 34 | mvn versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false -Dmaven.repo.local=./.m2 35 | mvn -f $(pwd)/org.structs4java.parent/pom.xml versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false -Dmaven.repo.local=./.m2 36 | mvn -f $(pwd)/structs4java-with-dependencies/pom.xml versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false -Dmaven.repo.local=./.m2 37 | mvn -f $(pwd)/structs4java-core/pom.xml versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false -Dmaven.repo.local=./.m2 38 | mvn -f $(pwd)/structs4java-maven-plugin/pom.xml versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false -Dmaven.repo.local=./.m2 39 | mvn -f $(pwd)/structs4java-maven-plugin-test/pom.xml versions:set -DnewVersion=${{ github.event.release.tag_name }} -DgenerateBackupPoms=false -Dmaven.repo.local=./.m2 40 | 41 | mvn versions:use-releases -DallowSnapshots=true -DexcludeReactor=false -DgenerateBackupPoms=false -Dmaven.repo.local=./.m2 42 | 43 | - name: Build with Maven 44 | uses: GabrielBB/xvfb-action@v1 45 | with: 46 | run: mvn clean install -Dmaven.repo.local=./.m2 -Declipse.p2.mirrors=false 47 | 48 | - name: Install GPG key 49 | run: | 50 | # Install gpg secret key 51 | cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import 52 | # Verify gpg secret key 53 | gpg --list-secret-keys --keyid-format LONG 54 | 55 | - name: Deploy to Maven Central 56 | env: 57 | OSSRH_USERNAME: ${{ secrets.SONATYPE_USERNAME }} 58 | OSSRH_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} 59 | run: | 60 | cd structs4java-core && mvn deploy -Prelease --settings ../deploy/settings.xml -Dmaven.repo.local=../.m2 -Drelease-composite=true -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} && cd .. 61 | cd structs4java-maven-plugin && mvn deploy -Prelease --settings ../deploy/settings.xml -Dmaven.repo.local=../.m2 -Drelease-composite=true -Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} && cd .. 62 | 63 | - name: Deploy to Gradle Portal 64 | env: 65 | GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PORTAL_PUBLISH_KEY }} 66 | GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PORTAL_PUBLISH_SECRET }} 67 | run: cd structs4java-gradle-plugin && ./gradlew publishPlugins -Dgradle.publish.key=${{ secrets.GRADLE_PORTAL_PUBLISH_KEY }} -Dgradle.publish.secret=${{ secrets.GRADLE_PORTAL_PUBLISH_SECRET }} -Pversion=${{ github.event.release.tag_name }} --no-configuration-cache 68 | 69 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | .settings/ 3 | .project 4 | .idea/ 5 | .classpath 6 | src-gen/ 7 | xtend-gen/ 8 | model/ 9 | workspace/ 10 | dependency-reduced-pom.xml 11 | bin/ 12 | /.metadata/ 13 | .m2/ 14 | *.gpg 15 | xvfb.log 16 | \?/ 17 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | RUN apt-get update && \ 4 | apt-get install -y software-properties-common 5 | 6 | RUN add-apt-repository ppa:openjdk-r/ppa 7 | RUN apt-get update && \ 8 | apt-get install -y openjdk-17-jdk 9 | 10 | RUN apt-get update && \ 11 | apt-get install -y \ 12 | libgtk-3-dev \ 13 | git 14 | 15 | RUN apt-get install -y xvfb 16 | 17 | ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 18 | 19 | RUN apt-get install -y wget 20 | RUN wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz -P /tmp && \ 21 | tar xf /tmp/apache-maven-*.tar.gz -C /opt && \ 22 | ln -s /opt/apache-maven-3.9.6 /opt/maven 23 | 24 | ENV PATH=/opt/maven/bin:$PATH 25 | 26 | RUN mkdir /workspace 27 | WORKDIR /workspace -------------------------------------------------------------------------------- /ROTATING-GPG-KEY.md: -------------------------------------------------------------------------------- 1 | - generate new GPG key: \ 2 | ```gpg --gen-key``` 3 | - export private key: \ 4 | ```gpg --export-secret-keys -a $KEY_ID | tr '\n' ',' | sed -e 's#,#\\n#g'``` 5 | - change GitHub secrets: 6 | * OSSRH_GPG_SECRET_KEY to the exported content from above 7 | * OSSRH_GPG_SECRET_KEY_PASSWORD to the passphrase used during key generation 8 | - publish public key (cf. https://central.sonatype.org/publish/requirements/gpg/#signing-a-file): 9 | - ```gpg --keyserver keyserver.ubuntu.com --send-keys $KEY_ID``` 10 | - ```gpg --keyserver keys.openpgp.org --send-keys $KEY_ID``` 11 | - ```gpg --keyserver pgp.mit.edu --send-keys $KEY_ID``` 12 | -------------------------------------------------------------------------------- /UPGRADING-XTEXT.md: -------------------------------------------------------------------------------- 1 | # Upgrading Xtext 2 | There's an example repository where we can pick the latest MANIFEST and target definitions: 3 | https://github.com/xtext/maven-xtext-example 4 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | docker build -t buildbox . 6 | 7 | docker run -i --rm \ 8 | -v "$(pwd)":/workspace \ 9 | --user "$(id -u):$(id -g)" \ 10 | -e DISPLAY=unix:0.0 \ 11 | -v /tmp/.X11-unix:/tmp/.X11-unix:ro \ 12 | buildbox \ 13 | bash -c "Xvfb :1 -screen 0 1024x768x16 &> xvfb.log & DISPLAY=:1.0 mvn clean install -Dmaven.repo.local=/workspace/.m2" 14 | -------------------------------------------------------------------------------- /deploy/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | central 5 | ${env.OSSRH_USERNAME} 6 | ${env.OSSRH_PASSWORD} 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.github.marc-christian-schulze.structs4java 5 | examples 6 | 1.0.54-SNAPSHOT 7 | pom 8 | 9 | 10 | zip-file-format 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/zip-file-format/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.github.marc-christian-schulze.structs4java 5 | examples-zip-file-format 6 | 1.0.54-SNAPSHOT 7 | 8 | 9 | UTF-8 10 | 17 11 | 17 12 | 13 | 14 | Example project showing how to define file structures using the example of ZIP files. 15 | 16 | 17 | 18 | 19 | com.github.marc-christian-schulze.structs4java 20 | structs4java-maven-plugin 21 | 1.0.54-SNAPSHOT 22 | 23 | 24 | compile-structs 25 | 26 | compile 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | junit 37 | junit 38 | 4.13.2 39 | test 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /examples/zip-file-format/src/main/structs/zip.structs: -------------------------------------------------------------------------------- 1 | package examples.zip; 2 | 3 | struct LocalFileHeader { 4 | uint8_t signature[4] const = { 0x50, 0x4b, 0x03, 0x04 }; 5 | uint16_t version; 6 | bitfield uint16_t { 7 | uint16_t generalPurposeFlags : 16; 8 | } 9 | uint16_t compressionMethod; 10 | uint16_t lastModificationTime; 11 | uint16_t lastModificationDate; 12 | uint32_t crc32OfUncompressedData; 13 | uint32_t compressedSizeInBytes; 14 | uint32_t uncompressedSizeInBytes; 15 | uint16_t fileNameLengthInBytes sizeof(fileName); 16 | uint16_t extraFieldLengthInBytes sizeof(extraFields); 17 | char fileName[]; 18 | ExtraFieldRecord extraFields[]; 19 | } 20 | 21 | struct ExtraFieldRecord { 22 | uint8_t signature[2]; 23 | uint16_t length sizeof(data); 24 | uint8_t data[]; 25 | } 26 | 27 | struct CentralDirectoryFileHeader { 28 | uint8_t signature[4] const = { 0x50, 0x4b, 0x01, 0x02 }; 29 | uint16_t versionMadeBy; 30 | uint16_t versionNeededToExtract; 31 | bitfield uint16_t { 32 | uint16_t generalPurposeFlags : 16; 33 | } 34 | uint16_t compressionMethod; 35 | uint16_t fileLastModificationTime; 36 | uint16_t fileLastModificationDate; 37 | uint32_t crc32OfUncompressedData; 38 | uint32_t compressedSizeInBytes; 39 | uint32_t uncompressedSizeInBytes; 40 | uint16_t fileNameLengthInBytes sizeof(fileName); 41 | uint16_t extraFieldLengthInBytes sizeof(extraFields); 42 | uint16_t fileCommentLengthInBytes sizeof(fileComment); 43 | uint16_t diskNumber; 44 | uint16_t internalAttributes; 45 | uint32_t externalAttributes; 46 | uint32_t relativeOffsetOfLocalFileHeader; 47 | char fileName[]; 48 | uint8_t extraFields[]; 49 | uint8_t fileComment[]; 50 | } 51 | 52 | struct EndOfCentralDirectoryRecord { 53 | uint8_t signature[4] const = { 0x50, 0x4b, 0x05, 0x06 }; 54 | uint16_t diskNumber; 55 | uint16_t diskWhereCentralDirectoryStarts; 56 | uint16_t numberOfCentralDirectoryRecordsOnThisDisk; 57 | uint16_t totalNumberOfCentralDirectoryRecords; 58 | uint32_t sizeOfCentralDirectoryInBytes; 59 | uint32_t offsetOfStartOfCentralDirectory; 60 | uint16_t commentLength sizeof(comment); 61 | uint8_t comment[]; 62 | } 63 | -------------------------------------------------------------------------------- /examples/zip-file-format/src/test/java/examples/zip/ZipFileReadingTest.java: -------------------------------------------------------------------------------- 1 | package examples.zip; 2 | 3 | import org.junit.Test; 4 | 5 | import java.io.IOException; 6 | import java.io.RandomAccessFile; 7 | import java.nio.ByteBuffer; 8 | import java.nio.ByteOrder; 9 | import java.nio.channels.FileChannel; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | import static org.junit.Assert.assertTrue; 13 | 14 | public class ZipFileReadingTest { 15 | 16 | @Test 17 | public void testUsingExampleZipFile() throws IOException { 18 | try(RandomAccessFile raf = new RandomAccessFile("src/test/resources/example.zip", "r")) { 19 | ByteBuffer buffer = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, raf.length()); 20 | 21 | // ZIP file specification requires little endian encoding 22 | buffer.order(ByteOrder.LITTLE_ENDIAN); 23 | 24 | // first, we need to search backwards in the ZIP file for the end of central directory 25 | assertTrue("No valid central directory found", seekToEndOfCentralDirectory(buffer)); 26 | 27 | // read from the buffer using the generated Java classes from the zip.structs file 28 | EndOfCentralDirectoryRecord eocd = EndOfCentralDirectoryRecord.read(buffer); 29 | 30 | assertEquals("We expect 3 entries in the ZIP file", 3, eocd.getNumberOfCentralDirectoryRecordsOnThisDisk()); 31 | assertEquals("We expect 3 entries in the ZIP file", 3, eocd.getTotalNumberOfCentralDirectoryRecords()); 32 | 33 | // seek to first entry of the central directory 34 | buffer.position((int) eocd.getOffsetOfStartOfCentralDirectory()); 35 | 36 | // let's retrieve the file names from the directory 37 | CentralDirectoryFileHeader cdfhDirectory = CentralDirectoryFileHeader.read(buffer); 38 | assertEquals(cdfhDirectory.getFileName(), "zip-content/"); 39 | 40 | CentralDirectoryFileHeader cdfhFile2 = CentralDirectoryFileHeader.read(buffer); 41 | assertEquals(cdfhFile2.getFileName(), "zip-content/file2.txt"); 42 | 43 | CentralDirectoryFileHeader cdfhFile1 = CentralDirectoryFileHeader.read(buffer); 44 | assertEquals(cdfhFile1.getFileName(), "zip-content/file1.txt"); 45 | 46 | // finally, let's read the file contents 47 | // first, we need to seek to the location of the local file header 48 | buffer.position((int) cdfhFile1.getRelativeOffsetOfLocalFileHeader()); 49 | // next, we read the local file header using our generated Java class 50 | LocalFileHeader fhFile1 = LocalFileHeader.read(buffer); 51 | // right after the header, the actual file content is placed 52 | byte[] contentFile1 = new byte[(int) fhFile1.getCompressedSizeInBytes()]; 53 | buffer.get(contentFile1); 54 | assertEquals("content file 1\n", new String(contentFile1)); 55 | 56 | // same for file 2 57 | buffer.position((int) cdfhFile2.getRelativeOffsetOfLocalFileHeader()); 58 | LocalFileHeader fhFile2 = LocalFileHeader.read(buffer); 59 | byte[] contentFile2 = new byte[(int) fhFile2.getCompressedSizeInBytes()]; 60 | buffer.get(contentFile2); 61 | assertEquals("content file 2\n", new String(contentFile2)); 62 | } 63 | } 64 | 65 | private static boolean seekToEndOfCentralDirectory(ByteBuffer buffer) throws IOException { 66 | int value; 67 | 68 | // we start scanning from the end of the file 69 | buffer.position(buffer.limit()); 70 | 71 | // first search for 0x06 72 | value = readPreviousByteFromBuffer(buffer); 73 | while(value != 0x06) { 74 | if(buffer.position() < 4) { 75 | return false; 76 | } 77 | value = readPreviousByteFromBuffer(buffer); 78 | } 79 | 80 | // now we search for 0x05 81 | value = readPreviousByteFromBuffer(buffer); 82 | while(value != 0x05) { 83 | if(buffer.position() < 3) { 84 | return false; 85 | } 86 | value = readPreviousByteFromBuffer(buffer); 87 | } 88 | 89 | // now we search for 0x4b 90 | value = readPreviousByteFromBuffer(buffer); 91 | while(value != 0x4b) { 92 | if(buffer.position() < 2) { 93 | return false; 94 | } 95 | value = readPreviousByteFromBuffer(buffer); 96 | } 97 | 98 | // finally we search for 0x50 99 | value = readPreviousByteFromBuffer(buffer); 100 | while(value != 0x50) { 101 | if(buffer.position() < 1) { 102 | return false; 103 | } 104 | value = readPreviousByteFromBuffer(buffer); 105 | } 106 | 107 | return true; 108 | } 109 | 110 | private static int readPreviousByteFromBuffer(ByteBuffer buffer) throws IOException { 111 | buffer.position(buffer.position() - 1); 112 | int value = buffer.get() & 0xFF; 113 | buffer.position(buffer.position() - 1); 114 | return value; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /examples/zip-file-format/src/test/java/examples/zip/ZipFileWritingTest.java: -------------------------------------------------------------------------------- 1 | package examples.zip; 2 | 3 | import org.junit.Test; 4 | import static org.junit.Assert.assertEquals; 5 | 6 | import java.io.ByteArrayInputStream; 7 | import java.io.IOException; 8 | import java.nio.ByteBuffer; 9 | import java.nio.ByteOrder; 10 | import java.util.zip.CRC32; 11 | import java.util.zip.Checksum; 12 | import java.util.zip.ZipEntry; 13 | import java.util.zip.ZipInputStream; 14 | 15 | public class ZipFileWritingTest { 16 | 17 | @Test 18 | public void testWritingZipFile() throws IOException { 19 | ByteBuffer buffer = ByteBuffer.allocate(4096); 20 | buffer.order(ByteOrder.LITTLE_ENDIAN); 21 | 22 | // our file content to store 23 | byte[] fileData = "example file content".getBytes("UTF-8"); 24 | 25 | // compute the CRC32 checksum of the file content 26 | Checksum checksum = new CRC32(); 27 | checksum.update(fileData, 0, fileData.length); 28 | long crc32 = checksum.getValue(); 29 | 30 | // first we create and write the local file header 31 | long positionOfLocalFileHeader = buffer.position(); 32 | LocalFileHeader fhFile = new LocalFileHeader(); 33 | fhFile.setFileName("example.txt"); 34 | fhFile.setCompressedSizeInBytes(fileData.length); 35 | fhFile.setUncompressedSizeInBytes(fileData.length); 36 | fhFile.setCrc32OfUncompressedData(crc32); 37 | fhFile.write(buffer); 38 | // right after the local file header, the actual file content needs to be stored 39 | buffer.put(fileData); 40 | 41 | // now we need to create the central directory header 42 | long positionOfFirstCentralDirectoryHeader = buffer.position(); 43 | CentralDirectoryFileHeader cdfh = new CentralDirectoryFileHeader(); 44 | cdfh.setFileName("example.txt"); 45 | cdfh.setCrc32OfUncompressedData(crc32); 46 | cdfh.setCompressedSizeInBytes(fileData.length); 47 | cdfh.setUncompressedSizeInBytes(fileData.length); 48 | cdfh.setRelativeOffsetOfLocalFileHeader(positionOfLocalFileHeader); 49 | cdfh.write(buffer); 50 | 51 | // finally, we need to write the closing end of central directory header 52 | EndOfCentralDirectoryRecord eocdr = new EndOfCentralDirectoryRecord(); 53 | eocdr.setOffsetOfStartOfCentralDirectory(positionOfFirstCentralDirectoryHeader); 54 | eocdr.setNumberOfCentralDirectoryRecordsOnThisDisk(1); 55 | eocdr.setTotalNumberOfCentralDirectoryRecords(1); 56 | eocdr.write(buffer); 57 | 58 | // now we read the ZIP file using Java on-board classes and verify 59 | ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(buffer.array())); 60 | ZipEntry fileEntry = zis.getNextEntry(); 61 | assertEquals("example.txt", fileEntry.getName()); 62 | byte[] fileContentRead = zis.readAllBytes(); 63 | assertEquals("example file content", new String(fileContentRead, "UTF-8")); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /examples/zip-file-format/src/test/resources/README.md: -------------------------------------------------------------------------------- 1 | The `example.zip` file was created without compression using 2 | ``` 3 | zip -0 -r example.zip zip-content/ 4 | ``` -------------------------------------------------------------------------------- /examples/zip-file-format/src/test/resources/example.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marc-christian-schulze/structs4java/d9b16a3143954306e95e157198fba9bb51c6b230/examples/zip-file-format/src/test/resources/example.zip -------------------------------------------------------------------------------- /examples/zip-file-format/src/test/resources/zip-content/file1.txt: -------------------------------------------------------------------------------- 1 | content file 1 2 | -------------------------------------------------------------------------------- /examples/zip-file-format/src/test/resources/zip-content/file2.txt: -------------------------------------------------------------------------------- 1 | content file 2 2 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.feature/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.structs4java.feature 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.feature/build.properties: -------------------------------------------------------------------------------- 1 | bin.includes = feature.xml 2 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.feature/feature.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 11 | 17 | 23 | 24 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.feature/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github.marc-christian-schulze.structs4java 6 | org.structs4java.parent 7 | 1.0.54-SNAPSHOT 8 | 9 | org.structs4java.feature 10 | eclipse-feature 11 | 12 | ${project.groupId}:${project.artifactId} 13 | Structs4Java is a code generator based on C/C++ structures. 14 | https://github.com/marc-christian-schulze/structs4java 15 | 16 | 17 | Marc-Christian Schulze 18 | Marc.Christian.Schulze@gmail.com 19 | GitHub 20 | https://github.com/marc-christian-schulze 21 | 22 | 23 | 24 | 25 | The Apache License, Version 2.0 26 | http://www.apache.org/licenses/LICENSE-2.0.txt 27 | 28 | 29 | 30 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 31 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 32 | https://github.com/marc-christian-schulze/structs4java/tree/master 33 | 34 | 35 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.structs4java.ide 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.xtext.ui.shared.xtextBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.ManifestBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.pde.SchemaBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.xtext.ui.shared.xtextNature 36 | org.eclipse.m2e.core.maven2Nature 37 | org.eclipse.pde.PluginNature 38 | org.eclipse.jdt.core.javanature 39 | 40 | 41 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/.settings/org.eclipse.xtend.core.Xtend.prefs: -------------------------------------------------------------------------------- 1 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/main/java.directory=xtend-gen 2 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/test/java.directory=src/test/generated-sources/xtend 3 | BuilderConfiguration.is_project_specific=true 4 | eclipse.preferences.version=1 5 | outlet.DEFAULT_OUTPUT.hideLocalSyntheticVariables=true 6 | outlet.DEFAULT_OUTPUT.installDslAsPrimarySource=false 7 | outlet.DEFAULT_OUTPUT.userOutputPerSourceFolder=true 8 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: org.structs4java.ide 4 | Bundle-Vendor: My Company 5 | Bundle-Version: 1.0.54.qualifier 6 | Bundle-SymbolicName: org.structs4java.ide; singleton:=true 7 | Bundle-ActivationPolicy: lazy 8 | Require-Bundle: org.structs4java, 9 | org.eclipse.xtext.ide, 10 | org.eclipse.xtext.xbase.ide, 11 | org.antlr.runtime;bundle-version="[3.2.0,3.2.1)" 12 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 13 | Export-Package: org.structs4java.ide.contentassist.antlr.internal, 14 | org.structs4java.ide.contentassist.antlr 15 | 16 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/bin/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/,\ 3 | xtend-gen/ 4 | bin.includes = .,\ 5 | META-INF/ 6 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/ 3 | bin.includes = .,\ 4 | META-INF/ 5 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github.marc-christian-schulze.structs4java 6 | org.structs4java.parent 7 | 1.0.54-SNAPSHOT 8 | 9 | org.structs4java.ide 10 | eclipse-plugin 11 | 12 | ${project.groupId}:${project.artifactId} 13 | Structs4Java is a code generator based on C/C++ structures. 14 | https://github.com/marc-christian-schulze/structs4java 15 | 16 | 17 | Marc-Christian Schulze 18 | Marc.Christian.Schulze@gmail.com 19 | GitHub 20 | https://github.com/marc-christian-schulze 21 | 22 | 23 | 24 | 25 | The Apache License, Version 2.0 26 | http://www.apache.org/licenses/LICENSE-2.0.txt 27 | 28 | 29 | 30 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 31 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 32 | https://github.com/marc-christian-schulze/structs4java/tree/master 33 | 34 | 35 | 36 | 37 | 38 | org.eclipse.xtend 39 | xtend-maven-plugin 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/src/org/structs4java/ide/Structs4JavaDslIdeModule.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Structs4Java 2.14.0 3 | */ 4 | package org.structs4java.ide 5 | 6 | 7 | /** 8 | * Use this class to register ide components. 9 | */ 10 | class Structs4JavaDslIdeModule extends AbstractStructs4JavaDslIdeModule { 11 | } 12 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ide/src/org/structs4java/ide/Structs4JavaDslIdeSetup.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Structs4Java 2.14.0 3 | */ 4 | package org.structs4java.ide 5 | 6 | import com.google.inject.Guice 7 | import org.eclipse.xtext.util.Modules2 8 | import org.structs4java.Structs4JavaDslRuntimeModule 9 | import org.structs4java.Structs4JavaDslStandaloneSetup 10 | 11 | /** 12 | * Initialization support for running Xtext languages as language servers. 13 | */ 14 | class Structs4JavaDslIdeSetup extends Structs4JavaDslStandaloneSetup { 15 | 16 | override createInjector() { 17 | Guice.createInjector(Modules2.mixin(new Structs4JavaDslRuntimeModule, new Structs4JavaDslIdeModule)) 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.target/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.target/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.target/org.structs4java.target.target: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.target/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github.marc-christian-schulze.structs4java 6 | org.structs4java.parent 7 | 1.0.54-SNAPSHOT 8 | 9 | org.structs4java.target 10 | eclipse-target-definition 11 | 12 | ${project.groupId}:${project.artifactId} 13 | Structs4Java is a code generator based on C/C++ structures. 14 | https://github.com/marc-christian-schulze/structs4java 15 | 16 | 17 | Marc-Christian Schulze 18 | Marc.Christian.Schulze@gmail.com 19 | GitHub 20 | https://github.com/marc-christian-schulze 21 | 22 | 23 | 24 | 25 | The Apache License, Version 2.0 26 | http://www.apache.org/licenses/LICENSE-2.0.txt 27 | 28 | 29 | 30 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 31 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 32 | https://github.com/marc-christian-schulze/structs4java/tree/master 33 | 34 | 35 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.structs4java.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.xtext.ui.shared.xtextBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.m2e.core.maven2Nature 36 | org.eclipse.jdt.core.javanature 37 | org.eclipse.pde.PluginNature 38 | org.eclipse.xtext.ui.shared.xtextNature 39 | 40 | 41 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/.settings/org.eclipse.xtend.core.Xtend.prefs: -------------------------------------------------------------------------------- 1 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/main/java.directory=xtend-gen 2 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/main/java.ignore=false 3 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/test/java.directory=src/test/generated-sources/xtend 4 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/test/java.ignore=false 5 | BuilderConfiguration.is_project_specific=true 6 | autobuilding=true 7 | eclipse.preferences.version=1 8 | is_project_specific=true 9 | outlet.DEFAULT_OUTPUT.cleanDirectory=false 10 | outlet.DEFAULT_OUTPUT.cleanupDerived=true 11 | outlet.DEFAULT_OUTPUT.createDirectory=true 12 | outlet.DEFAULT_OUTPUT.derived=true 13 | outlet.DEFAULT_OUTPUT.description=Output folder for generated Java files 14 | outlet.DEFAULT_OUTPUT.directory=xtend-gen 15 | outlet.DEFAULT_OUTPUT.hideLocalSyntheticVariables=true 16 | outlet.DEFAULT_OUTPUT.installDslAsPrimarySource=false 17 | outlet.DEFAULT_OUTPUT.keepLocalHistory=false 18 | outlet.DEFAULT_OUTPUT.name=DEFAULT_OUTPUT 19 | outlet.DEFAULT_OUTPUT.override=true 20 | outlet.DEFAULT_OUTPUT.userOutputPerSourceFolder=true 21 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: org.structs4java.tests 4 | Bundle-Vendor: My Company 5 | Bundle-Version: 1.0.54.qualifier 6 | Bundle-SymbolicName: org.structs4java.tests; singleton:=true 7 | Bundle-ActivationPolicy: lazy 8 | Require-Bundle: org.structs4java, 9 | org.eclipse.core.runtime, 10 | org.eclipse.xtend.lib, 11 | org.eclipse.ui.workbench;resolution:=optional, 12 | org.objectweb.asm;bundle-version="[9.0.0,10.0.0)";resolution:=optional, 13 | org.eclipse.xtext.testing, 14 | org.eclipse.xtext.xbase.testing, 15 | org.eclipse.xtext.xbase.lib;bundle-version="2.37.0" 16 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 17 | Export-Package: org.structs4java.tests;x-internal=true 18 | Import-Package: org.hamcrest.core, 19 | org.junit;version="4.5.0", 20 | org.junit.runners.model;version="4.5.0", 21 | org.junit.runner;version="4.5.0", 22 | org.junit.runners;version="4.5.0", 23 | org.junit.runner.manipulation;version="4.5.0", 24 | org.junit.runner.notification;version="4.5.0" 25 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/bin/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/,\ 3 | xtend-gen/ 4 | bin.includes = .,\ 5 | META-INF/ 6 | 7 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/,\ 3 | xtend-gen/ 4 | bin.includes = .,\ 5 | META-INF/ 6 | 7 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github.marc-christian-schulze.structs4java 6 | org.structs4java.parent 7 | 1.0.54-SNAPSHOT 8 | 9 | org.structs4java.tests 10 | eclipse-test-plugin 11 | 12 | ${project.groupId}:${project.artifactId} 13 | Structs4Java is a code generator based on C/C++ structures. 14 | https://github.com/marc-christian-schulze/structs4java 15 | 16 | 17 | Marc-Christian Schulze 18 | Marc.Christian.Schulze@gmail.com 19 | GitHub 20 | https://github.com/marc-christian-schulze 21 | 22 | 23 | 24 | 25 | The Apache License, Version 2.0 26 | http://www.apache.org/licenses/LICENSE-2.0.txt 27 | 28 | 29 | 30 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 31 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 32 | https://github.com/marc-christian-schulze/structs4java/tree/master 33 | 34 | 35 | 36 | 37 | 38 | org.eclipse.xtend 39 | xtend-maven-plugin 40 | 41 | 42 | org.eclipse.tycho 43 | tycho-surefire-plugin 44 | ${tycho-version} 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/src/org/structs4java/tests/DefaultValuesParsingTest.xtend: -------------------------------------------------------------------------------- 1 | package org.structs4java.tests 2 | 3 | import com.google.inject.Inject 4 | import org.eclipse.xtext.testing.InjectWith 5 | import org.eclipse.xtext.testing.XtextRunner 6 | import org.eclipse.xtext.testing.util.ParseHelper 7 | import org.junit.Test 8 | import org.junit.runner.RunWith 9 | import org.structs4java.structs4JavaDsl.IntegerMember 10 | import org.structs4java.structs4JavaDsl.FloatMember 11 | 12 | import static org.junit.Assert.assertEquals 13 | 14 | @RunWith(XtextRunner) 15 | @InjectWith(Structs4JavaDslInjectorProvider) 16 | class DefaultValuesParsingTest { 17 | 18 | @Inject 19 | ParseHelper parseHelper 20 | 21 | @Test 22 | def void structWithValidPrimitivesWithDefaultValues() { 23 | val pkg = parseHelper.parse(''' 24 | struct S { 25 | int8_t a = 1; 26 | uint8_t b = 2; 27 | int16_t c = 3; 28 | uint16_t d = 4; 29 | int32_t e = 5; 30 | uint32_t f = 6; 31 | int64_t g = 7; 32 | uint64_t h = 8; 33 | float i = 1.0; 34 | double j = 2.0; 35 | } 36 | ''') 37 | val struct = pkg.structs.get(0) 38 | 39 | assertEquals(1L, (struct.members.get(0) as IntegerMember).defaultValue) 40 | assertEquals(2L, (struct.members.get(1) as IntegerMember).defaultValue) 41 | assertEquals(3L, (struct.members.get(2) as IntegerMember).defaultValue) 42 | assertEquals(4L, (struct.members.get(3) as IntegerMember).defaultValue) 43 | assertEquals(5L, (struct.members.get(4) as IntegerMember).defaultValue) 44 | assertEquals(6L, (struct.members.get(5) as IntegerMember).defaultValue) 45 | assertEquals(7L, (struct.members.get(6) as IntegerMember).defaultValue) 46 | assertEquals(8L, (struct.members.get(7) as IntegerMember).defaultValue) 47 | assertEquals(1.0f, (struct.members.get(8) as FloatMember).defaultValue, 0.001f) 48 | assertEquals(2.0f, (struct.members.get(9) as FloatMember).defaultValue, 0.001f) 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.tests/src/org/structs4java/tests/Structs4JavaDslParsingTest.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.tests 5 | 6 | import com.google.inject.Inject 7 | import org.eclipse.xtext.testing.InjectWith 8 | import org.eclipse.xtext.testing.XtextRunner 9 | import org.eclipse.xtext.testing.util.ParseHelper 10 | import org.junit.Assert 11 | import org.junit.Test 12 | import org.junit.runner.RunWith 13 | import org.structs4java.structs4JavaDsl.IntegerMember 14 | import org.structs4java.structs4JavaDsl.ComplexTypeMember 15 | import org.structs4java.structs4JavaDsl.EnumDeclaration 16 | 17 | @RunWith(XtextRunner) 18 | @InjectWith(Structs4JavaDslInjectorProvider) 19 | class Structs4JavaDslParsingTest{ 20 | 21 | @Inject 22 | ParseHelper parseHelper 23 | 24 | @Test 25 | def void simpleEnum() { 26 | val pkg = parseHelper.parse(''' 27 | enum E : int16_t { 28 | A = 15, 29 | B = 18, 30 | C = 0xFffF 31 | } 32 | ''') 33 | Assert.assertNotNull(pkg) 34 | val enum = pkg.enums.get(0) 35 | Assert.assertNotNull(enum) 36 | Assert.assertEquals("E", enum.name) 37 | Assert.assertEquals("int16_t", enum.typename) 38 | Assert.assertEquals(3, enum.items.size) 39 | Assert.assertEquals("A", enum.items.get(0).name) 40 | Assert.assertEquals("B", enum.items.get(1).name) 41 | Assert.assertEquals("C", enum.items.get(2).name) 42 | 43 | Assert.assertEquals(15, enum.items.get(0).value) 44 | Assert.assertEquals(18, enum.items.get(1).value) 45 | Assert.assertEquals(0xFffF, enum.items.get(2).value) 46 | } 47 | 48 | @Test 49 | def void structWithEnum() { 50 | val pkg = parseHelper.parse(''' 51 | enum E : uint16_t { 52 | B = 0xCafe 53 | } 54 | 55 | struct A { 56 | int8_t myInt; 57 | E myEnum; 58 | } 59 | ''') 60 | 61 | Assert.assertNotNull(pkg) 62 | val struct = pkg.structs.get(0) 63 | Assert.assertEquals(2, struct.members.size) 64 | 65 | Assert.assertNotNull(struct) 66 | Assert.assertEquals("A", struct.name) 67 | 68 | val intMember = struct.members.get(0) as IntegerMember 69 | Assert.assertEquals("myInt", intMember.name) 70 | Assert.assertEquals("int8_t", intMember.typename) 71 | 72 | val enumMember = struct.members.get(1) as ComplexTypeMember 73 | Assert.assertEquals("myEnum", enumMember.name) 74 | 75 | Assert.assertEquals("E", enumMember.type.name) 76 | Assert.assertEquals("uint16_t", (enumMember.type as EnumDeclaration).typename) 77 | 78 | val items = (enumMember.type as EnumDeclaration).items 79 | Assert.assertEquals("B", items.get(0).name) 80 | Assert.assertEquals(0xCafe, items.get(0).value) 81 | } 82 | 83 | @Test 84 | def void structWithEnumInPackage() { 85 | val pkg = parseHelper.parse(''' 86 | package x.y.z; 87 | 88 | enum E : uint16_t { 89 | B = 0xCafe 90 | } 91 | 92 | struct A { 93 | int8_t myInt; 94 | E myEnum; 95 | } 96 | ''') 97 | 98 | Assert.assertNotNull(pkg) 99 | val struct = pkg.structs.get(0) 100 | Assert.assertEquals(2, struct.members.size) 101 | 102 | Assert.assertNotNull(struct) 103 | Assert.assertEquals("A", struct.name) 104 | 105 | val intMember = struct.members.get(0) as IntegerMember 106 | Assert.assertEquals("myInt", intMember.name) 107 | Assert.assertEquals("int8_t", intMember.typename) 108 | 109 | val enumMember = struct.members.get(1) as ComplexTypeMember 110 | Assert.assertEquals("myEnum", enumMember.name) 111 | 112 | Assert.assertEquals("E", enumMember.type.name) 113 | Assert.assertEquals("uint16_t", (enumMember.type as EnumDeclaration).typename) 114 | 115 | val items = (enumMember.type as EnumDeclaration).items 116 | Assert.assertEquals("B", items.get(0).name) 117 | Assert.assertEquals(0xCafe, items.get(0).value) 118 | } 119 | 120 | @Test 121 | def void structWithQualifiedEnum() { 122 | val pkg = parseHelper.parse(''' 123 | package x.y.z; 124 | 125 | enum E : uint16_t { 126 | B = 0xCafe 127 | } 128 | 129 | struct A { 130 | int8_t myInt; 131 | x.y.z.E myEnum; 132 | } 133 | ''') 134 | 135 | Assert.assertNotNull(pkg) 136 | Assert.assertNotNull("x.y.z", pkg.name) 137 | val struct = pkg.structs.get(0) 138 | Assert.assertEquals(2, struct.members.size) 139 | 140 | Assert.assertNotNull(struct) 141 | Assert.assertEquals("A", struct.name) 142 | 143 | val intMember = struct.members.get(0) as IntegerMember 144 | Assert.assertEquals("myInt", intMember.name) 145 | Assert.assertEquals("int8_t", intMember.typename) 146 | 147 | val enumMember = struct.members.get(1) as ComplexTypeMember 148 | Assert.assertEquals("myEnum", enumMember.name) 149 | 150 | println("struct: "+struct) 151 | println("enumMember.type: "+enumMember.type) 152 | Assert.assertEquals("E", enumMember.type.name) 153 | Assert.assertEquals("uint16_t", (enumMember.type as EnumDeclaration).typename) 154 | 155 | val items = (enumMember.type as EnumDeclaration).items 156 | Assert.assertEquals("B", items.get(0).name) 157 | Assert.assertEquals(0xCafe, items.get(0).value) 158 | } 159 | 160 | @Test 161 | def void structWithPackage() { 162 | val pkg = parseHelper.parse(''' 163 | package x.y.z; 164 | struct A { 165 | int8_t myInt; 166 | } 167 | ''') 168 | Assert.assertNotNull(pkg) 169 | Assert.assertNotNull("x.y.z", pkg.name) 170 | val struct = pkg.structs.get(0) 171 | Assert.assertNotNull(struct) 172 | Assert.assertEquals("A", struct.name) 173 | val member = struct.members.get(0) as IntegerMember 174 | Assert.assertEquals("myInt", member.name) 175 | Assert.assertEquals("int8_t", member.typename) 176 | } 177 | 178 | @Test 179 | def void simpleStruct() { 180 | val pkg = parseHelper.parse(''' 181 | struct A { 182 | int8_t myInt; 183 | } 184 | ''') 185 | Assert.assertNotNull(pkg) 186 | val struct = pkg.structs.get(0) 187 | Assert.assertNotNull(struct) 188 | Assert.assertEquals("A", struct.name) 189 | val member = struct.members.get(0) as IntegerMember 190 | Assert.assertEquals("myInt", member.name) 191 | Assert.assertEquals("int8_t", member.typename) 192 | } 193 | 194 | @Test 195 | def void nestedStruct() { 196 | val pkg = parseHelper.parse(''' 197 | struct A { 198 | int8_t myInt; 199 | } 200 | 201 | struct B { 202 | int16_t anotherInt; 203 | A nested; 204 | } 205 | ''') 206 | Assert.assertNotNull(pkg) 207 | 208 | val structA = pkg.structs.get(0) 209 | Assert.assertNotNull(structA) 210 | Assert.assertEquals("A", structA.name) 211 | val memberA = structA.members.get(0) as IntegerMember 212 | Assert.assertEquals("myInt", memberA.name) 213 | Assert.assertEquals("int8_t", memberA.typename) 214 | 215 | val structB = pkg.structs.get(1) 216 | Assert.assertNotNull(structB) 217 | Assert.assertEquals("B", structB.name) 218 | val member1 = structB.members.get(0) as IntegerMember 219 | Assert.assertEquals("anotherInt", member1.name) 220 | Assert.assertEquals("int16_t", member1.typename) 221 | val member2 = structB.members.get(1) as ComplexTypeMember 222 | Assert.assertEquals("nested", member2.name) 223 | Assert.assertEquals("A", member2.type.name) 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.structs4java.ui.tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.xtext.ui.shared.xtextNature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/.settings/org.eclipse.xtend.core.Xtend.prefs: -------------------------------------------------------------------------------- 1 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/main/java.directory=xtend-gen 2 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/test/java.directory=xtend-gen 3 | BuilderConfiguration.is_project_specific=true 4 | eclipse.preferences.version=1 5 | outlet.DEFAULT_OUTPUT.hideLocalSyntheticVariables=true 6 | outlet.DEFAULT_OUTPUT.installDslAsPrimarySource=false 7 | outlet.DEFAULT_OUTPUT.userOutputPerSourceFolder=true 8 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: org.structs4java.ui.tests 4 | Bundle-Vendor: My Company 5 | Bundle-Version: 1.0.54.qualifier 6 | Bundle-SymbolicName: org.structs4java.ui.tests; singleton:=true 7 | Bundle-ActivationPolicy: lazy 8 | Require-Bundle: org.structs4java.ui, 9 | org.junit;bundle-version="4.7.0", 10 | org.eclipse.core.runtime, 11 | org.eclipse.ui.workbench;resolution:=optional, 12 | org.eclipse.xtext.xbase.testing, 13 | org.eclipse.xtext.testing, 14 | org.eclipse.xtext.ui.testing, 15 | org.eclipse.xtext.xbase.ui.testing 16 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 17 | Export-Package: org.structs4java.ui.tests;x-internal=true 18 | Import-Package: org.hamcrest.core, 19 | org.junit;version="4.5.0", 20 | org.junit.runners.model;version="4.5.0", 21 | org.junit.runner;version="4.5.0", 22 | org.junit.runners;version="4.5.0", 23 | org.junit.runner.manipulation;version="4.5.0", 24 | org.junit.runner.notification;version="4.5.0" 25 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/bin/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/,\ 3 | xtend-gen/ 4 | bin.includes = .,\ 5 | META-INF/ 6 | 7 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/,\ 3 | xtend-gen/ 4 | bin.includes = .,\ 5 | META-INF/ 6 | 7 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui.tests/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github.marc-christian-schulze.structs4java 6 | org.structs4java.parent 7 | 1.0.54-SNAPSHOT 8 | 9 | org.structs4java.ui.tests 10 | eclipse-test-plugin 11 | 12 | ${project.groupId}:${project.artifactId} 13 | Structs4Java is a code generator based on C/C++ structures. 14 | https://github.com/marc-christian-schulze/structs4java 15 | 16 | 17 | Marc-Christian Schulze 18 | Marc.Christian.Schulze@gmail.com 19 | GitHub 20 | https://github.com/marc-christian-schulze 21 | 22 | 23 | 24 | 25 | The Apache License, Version 2.0 26 | http://www.apache.org/licenses/LICENSE-2.0.txt 27 | 28 | 29 | 30 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 31 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 32 | https://github.com/marc-christian-schulze/structs4java/tree/master 33 | 34 | 35 | 36 | 37 | 38 | org.eclipse.xtend 39 | xtend-maven-plugin 40 | 41 | 42 | org.eclipse.tycho 43 | tycho-surefire-plugin 44 | ${tycho-version} 45 | 46 | false 47 | true 48 | 49 | 50 | 51 | org.eclipse.tycho 52 | target-platform-configuration 53 | 54 | 55 | 56 | 59 | 60 | eclipse-feature 61 | org.eclipse.rcp 62 | 0.0.0 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | testing-on-mac 74 | 75 | 76 | mac 77 | 78 | 79 | 80 | -XstartOnFirstThread 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.structs4java.ui 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.xtext.ui.shared.xtextBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.m2e.core.maven2Nature 36 | org.eclipse.jdt.core.javanature 37 | org.eclipse.pde.PluginNature 38 | org.eclipse.xtext.ui.shared.xtextNature 39 | 40 | 41 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/.settings/org.eclipse.xtend.core.Xtend.prefs: -------------------------------------------------------------------------------- 1 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/main/java.directory=xtend-gen 2 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/main/java.ignore=false 3 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/test/java.directory=src/test/generated-sources/xtend 4 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/test/java.ignore=false 5 | BuilderConfiguration.is_project_specific=true 6 | autobuilding=true 7 | eclipse.preferences.version=1 8 | is_project_specific=true 9 | outlet.DEFAULT_OUTPUT.cleanDirectory=false 10 | outlet.DEFAULT_OUTPUT.cleanupDerived=true 11 | outlet.DEFAULT_OUTPUT.createDirectory=true 12 | outlet.DEFAULT_OUTPUT.derived=true 13 | outlet.DEFAULT_OUTPUT.description=Output folder for generated Java files 14 | outlet.DEFAULT_OUTPUT.directory=xtend-gen 15 | outlet.DEFAULT_OUTPUT.hideLocalSyntheticVariables=true 16 | outlet.DEFAULT_OUTPUT.installDslAsPrimarySource=false 17 | outlet.DEFAULT_OUTPUT.keepLocalHistory=false 18 | outlet.DEFAULT_OUTPUT.name=DEFAULT_OUTPUT 19 | outlet.DEFAULT_OUTPUT.override=true 20 | outlet.DEFAULT_OUTPUT.userOutputPerSourceFolder=true 21 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: org.structs4java.ui 4 | Bundle-Vendor: My Company 5 | Bundle-Version: 1.0.54.qualifier 6 | Bundle-SymbolicName: org.structs4java.ui; singleton:=true 7 | Bundle-ActivationPolicy: lazy 8 | Require-Bundle: org.structs4java, 9 | org.structs4java.ide, 10 | org.eclipse.xtext.ui, 11 | org.eclipse.xtext.ui.shared, 12 | org.eclipse.xtext.ui.codetemplates.ui, 13 | org.eclipse.ui.editors;bundle-version="3.5.0", 14 | org.eclipse.ui.ide;bundle-version="3.5.0", 15 | org.eclipse.ui, 16 | org.eclipse.compare, 17 | org.eclipse.xtext.builder, 18 | org.eclipse.xtend.lib;bundle-version="2.14.0";resolution:=optional, 19 | org.eclipse.xtext.common.types.ui, 20 | org.eclipse.xtext.xbase.ui, 21 | org.eclipse.jdt.debug.ui, 22 | org.eclipse.xtext.xbase.lib;bundle-version="2.37.0" 23 | Import-Package: org.apache.log4j 24 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 25 | Export-Package: org.structs4java.ui.quickfix, 26 | org.structs4java.ui.contentassist, 27 | org.structs4java.ui.internal 28 | Bundle-Activator: org.structs4java.ui.internal.Structs4javaActivator 29 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/bin/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/,\ 3 | xtend-gen/ 4 | bin.includes = .,\ 5 | META-INF/,\ 6 | plugin.xml 7 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/,\ 3 | xtend-gen/ 4 | bin.includes = .,\ 5 | META-INF/,\ 6 | plugin.xml 7 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github.marc-christian-schulze.structs4java 6 | org.structs4java.parent 7 | 1.0.54-SNAPSHOT 8 | 9 | org.structs4java.ui 10 | eclipse-plugin 11 | 12 | ${project.groupId}:${project.artifactId} 13 | Structs4Java is a code generator based on C/C++ structures. 14 | https://github.com/marc-christian-schulze/structs4java 15 | 16 | 17 | Marc-Christian Schulze 18 | Marc.Christian.Schulze@gmail.com 19 | GitHub 20 | https://github.com/marc-christian-schulze 21 | 22 | 23 | 24 | 25 | The Apache License, Version 2.0 26 | http://www.apache.org/licenses/LICENSE-2.0.txt 27 | 28 | 29 | 30 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 31 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 32 | https://github.com/marc-christian-schulze/structs4java/tree/master 33 | 34 | 35 | 36 | 37 | 38 | org.eclipse.xtend 39 | xtend-maven-plugin 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/src/org/structs4java/ui/CustomNatureAddingEditorCallback.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.ui; 2 | 3 | import org.eclipse.core.resources.IResource; 4 | import org.eclipse.jface.dialogs.IDialogConstants; 5 | import org.eclipse.jface.dialogs.MessageDialogWithToggle; 6 | import org.eclipse.xtext.builder.nature.Messages; 7 | import org.eclipse.xtext.builder.nature.ToggleXtextNatureAction; 8 | import org.eclipse.xtext.ui.editor.IXtextEditorCallback; 9 | import org.eclipse.xtext.ui.editor.XtextEditor; 10 | import org.eclipse.xtext.ui.util.DontAskAgainDialogs; 11 | 12 | import com.google.inject.Inject; 13 | 14 | public class CustomNatureAddingEditorCallback extends IXtextEditorCallback.NullImpl { 15 | private static final String ADD_XTEXT_NATURE = "add_xtext_nature"; 16 | @Inject 17 | private ToggleXtextNatureAction toggleNature; 18 | 19 | private @Inject DontAskAgainDialogs dialogs; 20 | 21 | @Override 22 | public void afterCreatePartControl(XtextEditor editor) { 23 | IResource resource = editor.getResource(); 24 | if (resource != null && !toggleNature.hasNature(resource.getProject()) && resource.getProject().isAccessible() 25 | && !resource.getProject().isHidden()) { 26 | String title = "Enable Structs4Java?"; 27 | String message = Messages.NatureAddingEditorCallback_MessageDialog_Msg0 + resource.getProject().getName() 28 | + " to a Structs4Java Project?"; 29 | boolean addNature = false; 30 | if (MessageDialogWithToggle.PROMPT.equals(dialogs.getUserDecision(ADD_XTEXT_NATURE))) { 31 | int userAnswer = dialogs.askUser(message, title, ADD_XTEXT_NATURE, editor.getEditorSite().getShell()); 32 | if (userAnswer == IDialogConstants.YES_ID) { 33 | addNature = true; 34 | } else if (userAnswer == IDialogConstants.CANCEL_ID) { 35 | return; 36 | } 37 | } else if (MessageDialogWithToggle.ALWAYS.equals(dialogs.getUserDecision(ADD_XTEXT_NATURE))) { 38 | addNature = true; 39 | } 40 | if (addNature) { 41 | toggleNature.toggleNature(resource.getProject()); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/src/org/structs4java/ui/Structs4JavaDslUiModule.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.ui 5 | 6 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor 7 | 8 | /** 9 | * Use this class to register components to be used within the Eclipse IDE. 10 | */ 11 | @FinalFieldsConstructor 12 | class Structs4JavaDslUiModule extends AbstractStructs4JavaDslUiModule { 13 | 14 | override bindIXtextEditorCallback() { 15 | return CustomNatureAddingEditorCallback 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/src/org/structs4java/ui/contentassist/Structs4JavaDslProposalProvider.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.ui.contentassist 5 | 6 | 7 | /** 8 | * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#content-assist 9 | * on how to customize the content assistant. 10 | */ 11 | class Structs4JavaDslProposalProvider extends AbstractStructs4JavaDslProposalProvider { 12 | } 13 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/src/org/structs4java/ui/labeling/Structs4JavaDslDescriptionLabelProvider.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.ui.labeling 5 | 6 | import org.eclipse.xtext.ui.label.DefaultDescriptionLabelProvider 7 | 8 | /** 9 | * Provides labels for IEObjectDescriptions and IResourceDescriptions. 10 | * 11 | * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#label-provider 12 | */ 13 | class Structs4JavaDslDescriptionLabelProvider extends DefaultDescriptionLabelProvider { 14 | 15 | // Labels and icons can be computed like this: 16 | 17 | // override text(IEObjectDescription ele) { 18 | // ele.name.toString 19 | // } 20 | // 21 | // override image(IEObjectDescription ele) { 22 | // ele.EClass.name + '.gif' 23 | // } 24 | } 25 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/src/org/structs4java/ui/labeling/Structs4JavaDslLabelProvider.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.ui.labeling 5 | 6 | import com.google.inject.Inject 7 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider 8 | import org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider 9 | 10 | /** 11 | * Provides labels for EObjects. 12 | * 13 | * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#label-provider 14 | */ 15 | class Structs4JavaDslLabelProvider extends DefaultEObjectLabelProvider { 16 | 17 | @Inject 18 | new(AdapterFactoryLabelProvider delegate) { 19 | super(delegate); 20 | } 21 | 22 | // Labels and icons can be computed like this: 23 | 24 | // def text(Greeting ele) { 25 | // 'A greeting to ' + ele.name 26 | // } 27 | // 28 | // def image(Greeting ele) { 29 | // 'Greeting.gif' 30 | // } 31 | } 32 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/src/org/structs4java/ui/outline/Structs4JavaDslOutlineTreeProvider.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.ui.outline 5 | 6 | import org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider 7 | 8 | /** 9 | * Customization of the default outline structure. 10 | * 11 | * See https://www.eclipse.org/Xtext/documentation/304_ide_concepts.html#outline 12 | */ 13 | class Structs4JavaDslOutlineTreeProvider extends DefaultOutlineTreeProvider { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java.ui/src/org/structs4java/ui/quickfix/Structs4JavaDslQuickfixProvider.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.ui.quickfix 5 | 6 | import org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider 7 | 8 | /** 9 | * Custom quickfixes. 10 | * 11 | * See https://www.eclipse.org/Xtext/documentation/310_eclipse_support.html#quick-fixes 12 | */ 13 | class Structs4JavaDslQuickfixProvider extends DefaultQuickfixProvider { 14 | 15 | // @Fix(Structs4JavaDslValidator.INVALID_NAME) 16 | // def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) { 17 | // acceptor.accept(issue, 'Capitalize name', 'Capitalize the name.', 'upcase.png') [ 18 | // context | 19 | // val xtextDocument = context.xtextDocument 20 | // val firstLetter = xtextDocument.get(issue.offset, 1) 21 | // xtextDocument.replace(issue.offset, 1, firstLetter.toUpperCase) 22 | // ] 23 | // } 24 | } 25 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | org.structs4java 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.xtext.ui.shared.xtextBuilder 25 | 26 | 27 | 28 | 29 | org.eclipse.m2e.core.maven2Builder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.m2e.core.maven2Nature 36 | org.eclipse.jdt.core.javanature 37 | org.eclipse.pde.PluginNature 38 | org.eclipse.xtext.ui.shared.xtextNature 39 | 40 | 41 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/.settings/org.eclipse.xtend.core.Xtend.prefs: -------------------------------------------------------------------------------- 1 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/main/java.directory=xtend-gen 2 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/main/java.ignore=false 3 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/test/java.directory=src/test/generated-sources/xtend 4 | //outlet.DEFAULT_OUTPUT.sourceFolder.src/test/java.ignore=false 5 | BuilderConfiguration.is_project_specific=true 6 | autobuilding=true 7 | eclipse.preferences.version=1 8 | is_project_specific=true 9 | outlet.DEFAULT_OUTPUT.cleanDirectory=false 10 | outlet.DEFAULT_OUTPUT.cleanupDerived=true 11 | outlet.DEFAULT_OUTPUT.createDirectory=true 12 | outlet.DEFAULT_OUTPUT.derived=true 13 | outlet.DEFAULT_OUTPUT.description=Output folder for generated Java files 14 | outlet.DEFAULT_OUTPUT.directory=xtend-gen 15 | outlet.DEFAULT_OUTPUT.hideLocalSyntheticVariables=true 16 | outlet.DEFAULT_OUTPUT.installDslAsPrimarySource=false 17 | outlet.DEFAULT_OUTPUT.keepLocalHistory=false 18 | outlet.DEFAULT_OUTPUT.name=DEFAULT_OUTPUT 19 | outlet.DEFAULT_OUTPUT.override=true 20 | outlet.DEFAULT_OUTPUT.userOutputPerSourceFolder=true 21 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: org.structs4java 4 | Bundle-Vendor: My Company 5 | Bundle-Version: 1.0.54.qualifier 6 | Bundle-SymbolicName: org.structs4java; singleton:=true 7 | Bundle-ActivationPolicy: lazy 8 | Require-Bundle: org.eclipse.xtext, 9 | org.eclipse.xtext.xbase, 10 | org.eclipse.equinox.common;bundle-version="3.5.0", 11 | org.eclipse.emf.ecore, 12 | org.eclipse.xtext.common.types, 13 | org.antlr.runtime;bundle-version="[3.2.0,3.2.1)", 14 | org.objectweb.asm;bundle-version="[9.0.0,10.0.0)";resolution:=optional, 15 | org.eclipse.xtext.util, 16 | org.eclipse.xtend.lib;bundle-version="2.13.0", 17 | org.eclipse.emf.common, 18 | org.eclipse.xtext.xbase.lib;bundle-version="2.37.0" 19 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 20 | Export-Package: org.structs4java.generator, 21 | org.structs4java.structs4JavaDsl.impl, 22 | org.structs4java.structs4JavaDsl, 23 | org.structs4java.scoping, 24 | org.structs4java.services, 25 | org.structs4java.parser.antlr, 26 | org.structs4java, 27 | org.structs4java.structs4JavaDsl.util, 28 | org.structs4java.validation, 29 | org.structs4java.serializer, 30 | org.structs4java.parser.antlr.internal, 31 | org.structs4java.formatting2, 32 | org.structs4java.jvmmodel 33 | Import-Package: org.apache.log4j 34 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/,\ 2 | src-gen/,\ 3 | xtend-gen/ 4 | bin.includes = model/generated/,\ 5 | .,\ 6 | META-INF/,\ 7 | plugin.xml 8 | additional.bundles = org.eclipse.xtext.xbase,\ 9 | org.eclipse.xtext.common.types,\ 10 | org.eclipse.xtext.xtext.generator,\ 11 | org.eclipse.emf.codegen.ecore,\ 12 | org.eclipse.emf.mwe.utils,\ 13 | org.eclipse.emf.mwe2.launch,\ 14 | org.eclipse.emf.mwe2.lib,\ 15 | org.objectweb.asm,\ 16 | org.apache.log4j,\ 17 | com.ibm.icu 18 | 19 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/plugin.xml_gen: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github.marc-christian-schulze.structs4java 6 | org.structs4java.parent 7 | 1.0.54-SNAPSHOT 8 | 9 | org.structs4java 10 | eclipse-plugin 11 | 12 | ${project.groupId}:${project.artifactId} 13 | Structs4Java is a code generator based on C/C++ structures. 14 | https://github.com/marc-christian-schulze/structs4java 15 | 16 | 17 | Marc-Christian Schulze 18 | Marc.Christian.Schulze@gmail.com 19 | GitHub 20 | https://github.com/marc-christian-schulze 21 | 22 | 23 | 24 | 25 | The Apache License, Version 2.0 26 | http://www.apache.org/licenses/LICENSE-2.0.txt 27 | 28 | 29 | 30 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 31 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 32 | https://github.com/marc-christian-schulze/structs4java/tree/master 33 | 34 | 35 | 36 | 37 | 38 | org.codehaus.mojo 39 | exec-maven-plugin 40 | 1.4.0 41 | 42 | 43 | mwe2Launcher 44 | generate-sources 45 | 46 | java 47 | 48 | 49 | 50 | 51 | org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher 52 | 53 | /${project.basedir}/src/org/structs4java/GenerateStructs4JavaDsl.mwe2 54 | -p 55 | rootPath=/${project.basedir}/.. 56 | 57 | compile 58 | true 59 | false 60 | 61 | 62 | 63 | org.eclipse.emf 64 | org.eclipse.emf.mwe2.launch 65 | ${mwe2Version} 66 | 67 | 68 | org.eclipse.xtext 69 | org.eclipse.xtext.xtext.generator 70 | ${xtextVersion} 71 | 72 | 73 | org.eclipse.xtext 74 | org.eclipse.xtext.xbase 75 | ${xtextVersion} 76 | 77 | 78 | org.eclipse.xtext 79 | org.eclipse.xtext.common.types 80 | ${xtextVersion} 81 | 82 | 83 | org.eclipse.xtext 84 | xtext-antlr-generator 85 | 2.1.1 86 | 87 | 88 | 89 | 90 | org.eclipse.xtend 91 | xtend-maven-plugin 92 | 93 | 94 | 95 | org.apache.maven.plugins 96 | maven-clean-plugin 97 | 98 | 99 | 100 | ${basedir}/../org.structs4java/src-gen/ 101 | 102 | **/* 103 | 104 | 105 | 106 | ${basedir}/../org.structs4java.tests/src-gen/ 107 | 108 | **/* 109 | 110 | 111 | 112 | ${basedir}/../org.structs4java.ide/src-gen/ 113 | 114 | **/* 115 | 116 | 117 | 118 | ${basedir}/../org.structs4java.ui/src-gen/ 119 | 120 | **/* 121 | 122 | 123 | 124 | ${basedir}/../org.structs4java.ui.tests/src-gen/ 125 | 126 | **/* 127 | 128 | 129 | 130 | ${basedir}/model/generated/ 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | org.eclipse.m2e 140 | lifecycle-mapping 141 | 1.0.0 142 | 143 | 144 | 145 | 146 | 147 | 148 | org.codehaus.mojo 149 | 150 | 151 | exec-maven-plugin 152 | 153 | 154 | [1.2.1,) 155 | 156 | 157 | java 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/GenerateStructs4JavaDsl.mwe2: -------------------------------------------------------------------------------- 1 | module org.structs4java.GenerateStructs4JavaDsl 2 | 3 | import org.eclipse.xtext.xtext.generator.* 4 | import org.eclipse.xtext.xtext.generator.model.project.* 5 | 6 | var rootPath = ".." 7 | 8 | Workflow { 9 | 10 | component = XtextGenerator { 11 | configuration = { 12 | project = StandardProjectConfig { 13 | baseName = "org.structs4java" 14 | rootPath = rootPath 15 | runtimeTest = { 16 | enabled = true 17 | } 18 | eclipsePlugin = { 19 | enabled = true 20 | } 21 | eclipsePluginTest = { 22 | enabled = true 23 | } 24 | createEclipseMetaData = true 25 | } 26 | code = { 27 | encoding = "UTF-8" 28 | fileHeader = "/*\n * generated by Structs4Java \${version}\n */" 29 | } 30 | } 31 | language = StandardLanguage { 32 | name = "org.structs4java.Structs4JavaDsl" 33 | fileExtensions = "structs" 34 | serializer = { 35 | generateStub = false 36 | } 37 | formatter = { 38 | generateStub = true 39 | } 40 | validator = { 41 | composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator" 42 | } 43 | fragment = scoping.ImportNamespacesScopingFragment2 { 44 | generateStub = true 45 | } 46 | fragment = exporting.QualifiedNamesFragment2 {} 47 | // provides the necessary bindings for java types integration 48 | fragment = types.TypesGeneratorFragment2 {} 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/Structs4JavaDsl.xtext: -------------------------------------------------------------------------------- 1 | grammar org.structs4java.Structs4JavaDsl hidden(WS) 2 | generate structs4JavaDsl "http://www.structs4java.org/Structs4JavaDsl" 3 | 4 | import "http://www.eclipse.org/emf/2002/Ecore" as ecore 5 | import "http://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes 6 | 7 | StructsFile: 8 | {StructsFile} 9 | 10 | SL_COMMENT* 11 | 12 | ('package' name=QualifiedName ';')? 13 | 14 | SL_COMMENT* 15 | 16 | (imports += Import)* 17 | 18 | (structs += StructDeclaration | enums += EnumDeclaration)* 19 | 20 | SL_COMMENT* 21 | ; 22 | 23 | Import: 24 | 'import' importedNamespace=QualifiedNameWithWildcard ';' 25 | ; 26 | 27 | QualifiedNameWithWildcard: 28 | QualifiedName '.*'? 29 | ; 30 | 31 | StructDeclaration: 32 | {StructDeclaration} 33 | (comments += SL_COMMENT)* 34 | 'struct' name=ID 35 | ('implements' implements+=[jvmTypes::JvmType|QualifiedName] (',' implements+=[jvmTypes::JvmType|QualifiedName])*)? 36 | '{' 37 | (members += Member)* 38 | SL_COMMENT* 39 | '}' 40 | ; 41 | 42 | Member: 43 | IntegerMember | FloatMember | StringMember | ComplexTypeMember | BitfieldMember 44 | ; 45 | 46 | EnumDeclaration: 47 | {EnumDeclaration} 48 | (comments += SL_COMMENT)* 49 | 'enum' name=ID ':' typename=INTEGER_TYPE '{' 50 | (items += Item)* 51 | SL_COMMENT* 52 | '}' 53 | ; 54 | 55 | Item: 56 | (comments += SL_COMMENT)* 57 | name=ID '=' value=LONG ','? 58 | ; 59 | 60 | BitfieldMember: 61 | (comments += SL_COMMENT)* 62 | 'bitfield' typename=INTEGER_TYPE (array=ArrayDimension)? ('padding' '(' padding=LONG ( ',' 'using' '=' using=LONG )? ')')? '{' 63 | (entries += BitfieldEntry)* 64 | '}' 65 | ; 66 | 67 | BitfieldEntry: 68 | (comments += SL_COMMENT)* typename=INTEGER_TYPE name=ID (array=ArrayDimension)? ':' bits=LONG ';' 69 | | (comments += SL_COMMENT)* typename=BOOLEAN_TYPE name=ID (array=ArrayDimension)? ':' bits=LONG ';' 70 | | (comments += SL_COMMENT)* type=[EnumDeclaration] name=ID (array=ArrayDimension)? ':' bits=LONG ';' 71 | ; 72 | 73 | ComplexTypeDeclaration: 74 | StructDeclaration | EnumDeclaration 75 | ; 76 | 77 | ComplexTypeMember: 78 | (comments += SL_COMMENT)* 79 | type=[ComplexTypeDeclaration|QualifiedName] name=ID 80 | (array=ArrayDimension)? 81 | ('padding' '(' padding=LONG ( ',' 'using' '=' using=LONG )? ')')? 82 | ';' 83 | | 84 | (comments += SL_COMMENT)* 85 | type=[EnumDeclaration|QualifiedName] name=ID 86 | (array=ArrayDimension)? 87 | ('padding' '(' padding=LONG ( ',' 'using' '=' using=LONG )? ')')? 88 | '=' defaultValue=[Item|QualifiedName] 89 | ';' 90 | ; 91 | 92 | IntegerMember: 93 | (comments += SL_COMMENT)* 94 | typename=INTEGER_TYPE name=ID 95 | ( 96 | ('sizeof' '(' sizeof=[Member] ')')? & 97 | ('sizeof' '(' sizeofThis?='this' ')')? & 98 | ('countof' '(' countof=[Member] ')')? 99 | ) 100 | ('padding' '(' padding=LONG ( ',' 'using' '=' using=LONG )? ')')? 101 | (constant='const')? 102 | ('=' defaultValue=LONG)? 103 | ';' 104 | | 105 | (comments += SL_COMMENT)* 106 | typename=INTEGER_TYPE name=ID 107 | array=ArrayDimension 108 | ( 109 | ('sizeof' '(' sizeof=[Member] ')')? & 110 | ('sizeof' '(' sizeofThis?='this' ')')? & 111 | ('countof' '(' countof=[Member] ')')? 112 | ) 113 | ('padding' '(' padding=LONG ( ',' 'using' '=' using=LONG )? ')')? 114 | (constant='const')? 115 | ('=' defaultValues=IntInitializerList)? 116 | ';' 117 | ; 118 | 119 | FloatMember: 120 | (comments += SL_COMMENT)* 121 | typename=FLOAT_TYPE name=ID 122 | ('padding' '(' padding=LONG ( ',' 'using' '=' using=LONG )? ')')? 123 | (constant='const')? 124 | ('=' defaultValue=FLOAT)? 125 | ';' 126 | | 127 | (comments += SL_COMMENT)* 128 | typename=FLOAT_TYPE name=ID 129 | array=ArrayDimension 130 | ('padding' '(' padding=LONG ( ',' 'using' '=' using=LONG )? ')')? 131 | (constant='const')? 132 | ('=' defaultValues=FloatInitializerList)? 133 | ';' 134 | ; 135 | 136 | StringMember: 137 | (comments += SL_COMMENT)* 138 | typename=STRING_TYPE name=ID 139 | (array=ArrayDimension)? 140 | ('encoding' '(' encoding=STRING ')')? 141 | ('padding' '(' padding=LONG ( ',' 'using' '=' using=LONG )? ')')? 142 | ('filler' '(' filler=LONG ')')? 143 | (nullTerminated='null-terminated')? 144 | (constant='const')? 145 | ('=' defaultValue=STRING)? 146 | ';' 147 | ; 148 | 149 | ArrayDimension: 150 | {ArrayDimension} '[' (dimension=LONG)? ']' 151 | ; 152 | 153 | IntInitializerList: 154 | {IntInitializerList} 155 | '{' items+=LONG (',' items+=LONG)* '}' 156 | ; 157 | 158 | FloatInitializerList: 159 | '{' items+=FLOAT (',' items+=FLOAT)* '}' 160 | ; 161 | 162 | QualifiedName: 163 | ID ('.' ID)* 164 | ; 165 | 166 | terminal FLOAT returns ecore::EFloat: ('0'..'9')+ '.' ('0'..'9')+; 167 | terminal LONG returns ecore::ELong: ('0'..'9')+ | '0x' ('0'..'9' | 'A'..'F' | 'a'..'f')+; 168 | terminal STRING : 169 | '"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' | 170 | "'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'" 171 | ; 172 | terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?; 173 | 174 | terminal WS : (' '|'\t'|'\r'|'\n')+; 175 | 176 | terminal INTEGER_TYPE: 177 | 'uint8_t' | 'uint16_t' | 'uint32_t' | 'uint64_t' | 178 | 'int8_t' | 'int16_t' | 'int32_t' | 'int64_t' 179 | ; 180 | 181 | terminal BOOLEAN_TYPE: 182 | 'boolean' 183 | ; 184 | 185 | terminal FLOAT_TYPE: 186 | 'float' | 'double' 187 | ; 188 | 189 | terminal STRING_TYPE: 190 | 'char' 191 | ; 192 | 193 | terminal ID: ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*; 194 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/Structs4JavaDslRuntimeModule.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java 5 | 6 | import org.structs4java.converter.Structs4JavaDslValueConverter 7 | import org.structs4java.scoping.MyImportedNamespaceAwareLocalScopeProvider 8 | import org.eclipse.xtext.resource.impl.SimpleResourceDescriptionsBasedContainerManager 9 | 10 | /** 11 | * Use this class to register components to be used at runtime / without the Equinox extension registry. 12 | */ 13 | class Structs4JavaDslRuntimeModule extends AbstractStructs4JavaDslRuntimeModule { 14 | 15 | override bindIValueConverterService() { 16 | return Structs4JavaDslValueConverter; 17 | } 18 | 19 | override bindIJvmTypeProvider$Factory() { 20 | super.bindIJvmTypeProvider$Factory() 21 | } 22 | 23 | override bindIQualifiedNameProvider() { 24 | return Structs4JavaQualifiedNameProvider; 25 | } 26 | 27 | override bindIScopeProvider() { 28 | return MyImportedNamespaceAwareLocalScopeProvider; 29 | } 30 | 31 | override bindIContainer$Manager() { 32 | return SimpleResourceDescriptionsBasedContainerManager; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/Structs4JavaDslStandaloneSetup.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java 5 | 6 | 7 | /** 8 | * Initialization support for running Xtext languages without Equinox extension registry. 9 | */ 10 | class Structs4JavaDslStandaloneSetup extends Structs4JavaDslStandaloneSetupGenerated { 11 | 12 | def static void doSetup() { 13 | new Structs4JavaDslStandaloneSetup().createInjectorAndDoEMFRegistration() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/Structs4JavaQualifiedNameProvider.java: -------------------------------------------------------------------------------- 1 | package org.structs4java; 2 | 3 | import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider; 4 | 5 | public class Structs4JavaQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider { 6 | 7 | } -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/converter/Structs4JavaDslValueConverter.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.converter; 2 | 3 | import org.eclipse.xtext.common.services.DefaultTerminalConverters; 4 | import org.eclipse.xtext.conversion.IValueConverter; 5 | import org.eclipse.xtext.conversion.ValueConverter; 6 | import org.eclipse.xtext.conversion.ValueConverterException; 7 | import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter; 8 | import org.eclipse.xtext.conversion.impl.INTValueConverter; 9 | import org.eclipse.xtext.nodemodel.INode; 10 | import org.eclipse.xtext.util.Strings; 11 | 12 | public class Structs4JavaDslValueConverter extends DefaultTerminalConverters { 13 | 14 | @Override 15 | @ValueConverter(rule = "INT") 16 | public IValueConverter INT() { 17 | return new INTValueConverter(); 18 | } 19 | 20 | @ValueConverter(rule = "LONG") 21 | public IValueConverter LONG() { 22 | return new LONGValueConverter(); 23 | } 24 | 25 | private static final class INTValueConverter extends AbstractLexerBasedConverter { 26 | @Override 27 | public Integer toValue(String string, INode node) { 28 | if (Strings.isEmpty(string)) 29 | throw new ValueConverterException("Couldn't convert empty string to an int value.", node, null); 30 | 31 | try { 32 | return Integer.decode(string); 33 | } catch (NumberFormatException e) { 34 | throw new ValueConverterException("Couldn't convert empty string to an int value.", node, e); 35 | } 36 | } 37 | } 38 | 39 | private static final class LONGValueConverter extends AbstractLexerBasedConverter { 40 | @Override 41 | public Long toValue(String string, INode node) { 42 | if (Strings.isEmpty(string)) 43 | throw new ValueConverterException("Couldn't convert empty string to an long value.", node, null); 44 | 45 | try { 46 | return Long.decode(string); 47 | } catch (NumberFormatException e) { 48 | throw new ValueConverterException("Couldn't convert empty string to an long value.", node, e); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/formatting2/Structs4JavaDslFormatter.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Structs4Java 2.10.0 3 | */ 4 | package org.structs4java.formatting2 5 | 6 | import org.eclipse.xtext.formatting2.AbstractFormatter2 7 | import org.eclipse.xtext.formatting2.IFormattableDocument 8 | import org.structs4java.structs4JavaDsl.EnumDeclaration 9 | import org.structs4java.structs4JavaDsl.Import 10 | import org.structs4java.structs4JavaDsl.Member 11 | import org.structs4java.structs4JavaDsl.StructDeclaration 12 | import org.structs4java.structs4JavaDsl.Item 13 | import org.structs4java.structs4JavaDsl.Structs4JavaDslPackage 14 | import org.eclipse.xtext.EcoreUtil2 15 | 16 | class Structs4JavaDslFormatter extends AbstractFormatter2 { 17 | 18 | def dispatch void format(org.structs4java.structs4JavaDsl.StructsFile structsFile, 19 | extension IFormattableDocument document) { 20 | // TODO: format HiddenRegions around keywords, attributes, cross references, etc. 21 | for (Import imports : structsFile.getImports()) { 22 | imports.format; 23 | } 24 | for (StructDeclaration structs : structsFile.getStructs()) { 25 | structs.format; 26 | } 27 | for (EnumDeclaration enums : structsFile.getEnums()) { 28 | enums.format; 29 | } 30 | 31 | structsFile.regionFor.keyword(";").append[newLines = 2] 32 | structsFile.regionFor.keyword(";").prepend[noSpace] 33 | } 34 | 35 | def dispatch void format(StructDeclaration structDeclaration, extension IFormattableDocument document) { 36 | val open = structDeclaration.regionFor.keyword("{") 37 | val close = structDeclaration.regionFor.keyword("}") 38 | 39 | open.prepend[newLine].append[newLine] 40 | close.append[newLines = 2] 41 | interior(open, close)[indent] 42 | 43 | for (Member members : structDeclaration.getMembers()) { 44 | members.format; 45 | } 46 | } 47 | 48 | def dispatch void format(Import imp, extension IFormattableDocument document) { 49 | if ((imp.eContainer as org.structs4java.structs4JavaDsl.StructsFile).getImports().lastOrNull == imp) { 50 | imp.regionFor.keyword(";").prepend[noSpace].append[newLines = 2] 51 | } else { 52 | imp.regionFor.keyword(";").prepend[noSpace].append[newLine] 53 | } 54 | } 55 | 56 | def dispatch void format(Member member, extension IFormattableDocument document) { 57 | val nextMember = EcoreUtil2.getNextSibling(member) as Member 58 | if (nextMember !== null && nextMember.comments.size > 0) { 59 | member.regionFor.keyword(";").prepend[noSpace].append[newLines = 2] 60 | } else { 61 | member.regionFor.keyword(";").prepend[noSpace].append[newLine] 62 | } 63 | 64 | val comments = member.regionFor.features(Structs4JavaDslPackage.Literals.MEMBER__COMMENTS) 65 | comments.forEach[append[newLine]] 66 | } 67 | 68 | def dispatch void format(EnumDeclaration _enum, extension IFormattableDocument document) { 69 | val open = _enum.regionFor.keyword("{") 70 | val close = _enum.regionFor.keyword("}") 71 | 72 | open.prepend[newLine].append[newLine] 73 | close.prepend[newLine].append[newLines = 2] 74 | interior(open, close)[indent] 75 | 76 | _enum.regionFor.keyword(":").surround[oneSpace] 77 | 78 | for (Item itm : _enum.items) { 79 | itm.format 80 | } 81 | } 82 | 83 | def dispatch void format(Item item, extension IFormattableDocument document) { 84 | var region = item.regionFor.keyword(",") 85 | if(region !== null) { 86 | region.prepend[noSpace] 87 | } 88 | 89 | if (region === null) { 90 | region = item.regionFor.feature(Structs4JavaDslPackage.Literals.ITEM__VALUE); 91 | } 92 | 93 | val nextItem = EcoreUtil2.getNextSibling(item) as Item 94 | if (nextItem !== null && nextItem.comments.size > 0) { 95 | region.prepend[noSpace].append[newLines = 2] 96 | } else { 97 | region.append[newLine] 98 | } 99 | 100 | item.regionFor.keyword("=").surround[oneSpace] 101 | 102 | val comments = item.regionFor.features(Structs4JavaDslPackage.Literals.ITEM__COMMENTS) 103 | comments.forEach[append[newLine]] 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/generator/EnumGenerator.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.generator 5 | 6 | import org.structs4java.structs4JavaDsl.EnumDeclaration 7 | import org.structs4java.structs4JavaDsl.StructsFile 8 | import org.structs4java.structs4JavaDsl.Item 9 | 10 | /** 11 | * Generates code from your model files on save. 12 | * 13 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation 14 | */ 15 | class EnumGenerator { 16 | 17 | def compile(StructsFile structsFile, EnumDeclaration enumDecl) ''' 18 | «packageDeclaration(structsFile)» 19 | 20 | «printComments(enumDecl)» 21 | public enum «enumDecl.name» { 22 | 23 | «items(enumDecl)» 24 | 25 | «reader(enumDecl)» 26 | «writer(enumDecl)» 27 | 28 | public long getValue() { 29 | return value; 30 | } 31 | 32 | private «enumDecl.name»(long value) { 33 | this.value = value; 34 | } 35 | 36 | private long value; 37 | } 38 | ''' 39 | 40 | def printComments(EnumDeclaration typeDecl) ''' 41 | /** 42 | «FOR comment : typeDecl.comments» 43 | * «comment.substring(2).trim()» 44 | «ENDFOR» 45 | */ 46 | ''' 47 | 48 | def printComments(Item item) ''' 49 | /** 50 | «FOR comment : item.comments» 51 | * «comment.substring(2).trim()» 52 | «ENDFOR» 53 | */ 54 | ''' 55 | 56 | def items(EnumDeclaration enumDecl) ''' 57 | «FOR i : enumDecl.items SEPARATOR "," AFTER ";"» 58 | «printComments(i)» 59 | «i.name»(«i.value»L) 60 | «ENDFOR» 61 | ''' 62 | 63 | def reader(EnumDeclaration enumDecl) ''' 64 | public static «enumDecl.name» read(java.nio.ByteBuffer buf, boolean partialRead) throws java.io.IOException { 65 | return read(buf); 66 | } 67 | 68 | public static «enumDecl.name» read(java.nio.ByteBuffer buf) throws java.io.IOException { 69 | «read(enumDecl)» 70 | try { 71 | return fromValue(value); 72 | } catch(IllegalArgumentException e) { 73 | throw new java.io.IOException(e); 74 | } 75 | } 76 | 77 | public static «enumDecl.name» fromValue(long value) throws IllegalArgumentException { 78 | «FOR f : enumDecl.items» 79 | if(value == «f.value»L) { 80 | return «f.name»; 81 | } 82 | «ENDFOR» 83 | throw new IllegalArgumentException(String.format("Unknown enum value: 0x%X", value)); 84 | } 85 | ''' 86 | 87 | def read(EnumDeclaration enumDecl) { 88 | switch (enumDecl.typename) { 89 | case "int8_t": '''long value = buf.get();''' 90 | case "uint8_t": '''long value = buf.get() & 0xFFL;''' 91 | case "int16_t": '''long value = buf.getShort();''' 92 | case "uint16_t": '''long value = buf.getShort() & 0xFFFFL;''' 93 | case "int32_t": '''long value = buf.getInt();''' 94 | case "uint32_t": '''long value = buf.getInt() & 0xFFFFFFFFL;''' 95 | case "int64_t": '''long value = buf.getLong();''' 96 | case "uint64_t": '''long value = buf.getLong();''' 97 | } 98 | } 99 | 100 | def writer(EnumDeclaration enumDecl) ''' 101 | public void write(java.nio.ByteBuffer buf) throws java.io.IOException { 102 | «write(enumDecl)» 103 | } 104 | ''' 105 | 106 | def write(EnumDeclaration enumDecl) { 107 | switch (enumDecl.typename) { 108 | case "int8_t": '''buf.put((byte)(this.value));''' 109 | case "uint8_t": '''buf.put((byte)(this.value & 0xFFL));''' 110 | case "int16_t": '''buf.putShort((short)(this.value));''' 111 | case "uint16_t": '''buf.putShort((short)(this.value & 0xFFFFL));''' 112 | case "int32_t": '''buf.putInt((int)(this.value));''' 113 | case "uint32_t": '''buf.putInt((int)(this.value & 0xFFFFFFFFL));''' 114 | case "int64_t": '''buf.putLong(this.value);''' 115 | case "uint64_t": '''buf.putLong(this.value);''' 116 | } 117 | } 118 | 119 | def packageDeclaration(StructsFile structsFile) ''' 120 | «IF structsFile.name !== null && !structsFile.name.empty» 121 | package «structsFile.name»; 122 | «ENDIF» 123 | ''' 124 | } 125 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/generator/Structs4JavaDslGenerator.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.generator 5 | 6 | import org.eclipse.emf.ecore.resource.Resource 7 | import org.eclipse.xtext.generator.AbstractGenerator 8 | import org.eclipse.xtext.generator.IFileSystemAccess2 9 | import org.eclipse.xtext.generator.IGeneratorContext 10 | import org.structs4java.structs4JavaDsl.ComplexTypeDeclaration 11 | import org.structs4java.structs4JavaDsl.StructsFile 12 | 13 | /** 14 | * Generates code from your model files on save. 15 | * 16 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation 17 | */ 18 | class Structs4JavaDslGenerator extends AbstractGenerator { 19 | 20 | override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { 21 | val enumGen = new EnumGenerator 22 | val structGen = new StructGenerator 23 | 24 | for (pkg : resource.allContents.toIterable.filter(StructsFile)) { 25 | for (struct : pkg.structs) { 26 | fsa.generateFile(javaType(struct).replace('.', '/') + ".java", structGen.compile(pkg, struct)) 27 | } 28 | 29 | for (enumDecl : pkg.enums) { 30 | fsa.generateFile(javaType(enumDecl).replace('.', '/') + ".java", enumGen.compile(pkg, enumDecl)) 31 | } 32 | } 33 | } 34 | 35 | def javaType(ComplexTypeDeclaration type) { 36 | val pkg = type.eContainer as StructsFile 37 | if (pkg !== null && pkg.name !== null && !pkg.name.empty) { 38 | return pkg.name + "." + type.name 39 | } 40 | return type.name 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/jvmmodel/Structs4JavaDslJvmModelInferrer.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Structs4Java 2.10.0 3 | */ 4 | package org.structs4java.jvmmodel 5 | 6 | import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer 7 | import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor 8 | 9 | /** 10 | *

Infers a JVM model from the source model.

11 | * 12 | *

The JVM model should contain all elements that would appear in the Java code 13 | * which is generated from the source model. Other models link against the JVM model rather than the source model.

14 | */ 15 | class Structs4JavaDslJvmModelInferrer extends AbstractModelInferrer { 16 | 17 | /** 18 | * The dispatch method {@code infer} is called for each instance of the 19 | * given element's type that is contained in a resource. 20 | * 21 | * @param element 22 | * the model to create one or more 23 | * {@link org.eclipse.xtext.common.types.JvmDeclaredType declared 24 | * types} from. 25 | * @param acceptor 26 | * each created 27 | * {@link org.eclipse.xtext.common.types.JvmDeclaredType type} 28 | * without a container should be passed to the acceptor in order 29 | * get attached to the current resource. The acceptor's 30 | * {@link IJvmDeclaredTypeAcceptor#accept(org.eclipse.xtext.common.types.JvmDeclaredType) 31 | * accept(..)} method takes the constructed empty type for the 32 | * pre-indexing phase. This one is further initialized in the 33 | * indexing phase using the lambda you pass as the last argument. 34 | * @param isPreIndexingPhase 35 | * whether the method is called in a pre-indexing phase, i.e. 36 | * when the global index is not yet fully updated. You must not 37 | * rely on linking using the index if isPreIndexingPhase is 38 | * true. 39 | */ 40 | def dispatch void infer(org.structs4java.structs4JavaDsl.StructsFile element, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) { 41 | // Here you explain how your model is mapped to Java elements, by writing the actual translation code. 42 | 43 | // An implementation for the initial hello world example could look like this: 44 | // acceptor.accept(element.toClass("my.company.greeting.MyGreetings")) [ 45 | // for (greeting : element.greetings) { 46 | // members += greeting.toMethod("hello" + greeting.name, typeRef(String)) [ 47 | // body = ''' 48 | // return "Hello «greeting.name»"; 49 | // ''' 50 | // ] 51 | // } 52 | // ] 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/scoping/MyImportedNamespaceAwareLocalScopeProvider.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.scoping; 2 | 3 | import java.util.List; 4 | 5 | import org.eclipse.emf.ecore.EObject; 6 | import org.eclipse.xtext.naming.QualifiedName; 7 | import org.eclipse.xtext.scoping.impl.ImportNormalizer; 8 | import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider; 9 | import org.structs4java.structs4JavaDsl.StructsFile; 10 | 11 | /** 12 | * @see https://nittka.github.io/2011/08/07/scoping3.html 13 | * @author azrael 14 | * 15 | */ 16 | public class MyImportedNamespaceAwareLocalScopeProvider extends ImportedNamespaceAwareLocalScopeProvider { 17 | 18 | @Override 19 | protected List getImportedNamespaceResolvers(EObject context, boolean ignoreCase) { 20 | List resolvers = super.getImportedNamespaceResolvers(context, ignoreCase); 21 | boolean wildcard = true; 22 | resolvers.add(new ImportNormalizer(getPackageName(context), wildcard, ignoreCase)); 23 | return resolvers; 24 | } 25 | 26 | private QualifiedName getPackageName(EObject eobject) { 27 | if (eobject instanceof StructsFile) { 28 | StructsFile file = (StructsFile) eobject; 29 | if (file.getName() == null) { 30 | return QualifiedName.create(""); 31 | } 32 | return QualifiedName.create(file.getName().split("\\.")); 33 | } 34 | return getPackageName(eobject.eContainer()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/scoping/Structs4JavaDslScopeProvider.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.scoping 5 | 6 | import org.eclipse.emf.ecore.EObject 7 | import org.eclipse.emf.ecore.EReference 8 | import org.structs4java.structs4JavaDsl.Structs4JavaDslPackage 9 | import org.structs4java.structs4JavaDsl.StructDeclaration 10 | 11 | /** 12 | * This class contains custom scoping description. 13 | * 14 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#scoping 15 | * on how and when to use it. 16 | */ 17 | class Structs4JavaDslScopeProvider extends AbstractStructs4JavaDslScopeProvider { 18 | 19 | override getScope(EObject context, EReference reference) { 20 | if(context instanceof StructDeclaration && 21 | reference == Structs4JavaDslPackage.Literals.STRUCT_DECLARATION__IMPLEMENTS) { 22 | 23 | val scope = super.getScope(context, reference) 24 | println("Scope for " + reference + " is: " + scope) 25 | return scope 26 | } 27 | 28 | super.getScope(context, reference) 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /org.structs4java.parent/org.structs4java/src/org/structs4java/validation/Structs4JavaDslValidator.xtend: -------------------------------------------------------------------------------- 1 | /* 2 | * generated by Xtext 2.10.0 3 | */ 4 | package org.structs4java.validation 5 | 6 | import org.eclipse.xtext.validation.Check 7 | import org.structs4java.structs4JavaDsl.IntegerMember 8 | import org.structs4java.structs4JavaDsl.FloatMember 9 | import org.structs4java.structs4JavaDsl.Member 10 | import org.structs4java.structs4JavaDsl.StructDeclaration 11 | import org.structs4java.structs4JavaDsl.Structs4JavaDslPackage 12 | import org.structs4java.structs4JavaDsl.StringMember 13 | 14 | /** 15 | * This class contains custom validation rules. 16 | * 17 | * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation 18 | */ 19 | class Structs4JavaDslValidator extends AbstractStructs4JavaDslValidator { 20 | 21 | @Check 22 | def checkArrayDimension(Member m) { 23 | if(m.array === null) { 24 | return; 25 | } 26 | 27 | if(m.array.dimension == 0) { 28 | if(m instanceof StringMember) { 29 | return; 30 | } 31 | 32 | if(getSizeOfFor(m) !== null) { 33 | return; 34 | } 35 | 36 | val struct = m.eContainer as StructDeclaration; 37 | val idx = struct.members.indexOf(m) 38 | 39 | if(idx+1 < struct.members.size()) { 40 | error('Only the last member is allowed to be greedy!', m, Structs4JavaDslPackage.Literals.MEMBER__ARRAY) 41 | } 42 | 43 | } else { 44 | if(getCountOfFor(m) !== null) { 45 | error('Either array dimension or countof must be specified but not both!', m, Structs4JavaDslPackage.Literals.MEMBER__ARRAY) 46 | } 47 | 48 | if(getSizeOfFor(m) !== null) { 49 | error('Either array dimension or sizeof must be specified but not both!', m, Structs4JavaDslPackage.Literals.MEMBER__ARRAY) 50 | } 51 | } 52 | } 53 | 54 | @Check 55 | def checkArrayDimensionIsBeforeDynamicElement(Member m) { 56 | if(m.array === null) { 57 | return; 58 | } 59 | 60 | if(m.array.dimension == 0) { 61 | val struct = m.eContainer as StructDeclaration; 62 | val countOf = getCountOfFor(m) 63 | 64 | val countOfIdx = struct.members.indexOf(countOf) 65 | val memberIdx = struct.members.indexOf(m) 66 | if(countOfIdx > memberIdx) { 67 | error('Size of a dynamic element must be specified before the actual field!', m, Structs4JavaDslPackage.Literals.MEMBER__ARRAY) 68 | error('Size of a dynamic element must be specified before the actual field!', countOf, Structs4JavaDslPackage.Literals.INTEGER_MEMBER__COUNTOF) 69 | } 70 | } 71 | } 72 | 73 | @Check 74 | def checkSizeIsBeforeDynamicElement(Member m) { 75 | if(m.array.dimension == 0) { 76 | val struct = m.eContainer as StructDeclaration; 77 | val sizeOf = getSizeOfFor(m) 78 | 79 | val sizeOfIdx = struct.members.indexOf(sizeOf) 80 | val memberIdx = struct.members.indexOf(m) 81 | if(sizeOfIdx > memberIdx) { 82 | error('Size of a dynamic element must be specified before the actual field!', m, Structs4JavaDslPackage.Literals.MEMBER__ARRAY) 83 | error('Size of a dynamic element must be specified before the actual field!', sizeOf, Structs4JavaDslPackage.Literals.INTEGER_MEMBER__SIZEOF) 84 | } 85 | } 86 | } 87 | 88 | @Check 89 | def disable64BitSizeOfAndCountOf(Member m) { 90 | if(m instanceof IntegerMember) { 91 | if(m.sizeof !== null || m.countof !== null || m.sizeofThis) { 92 | if(m.typename.equals("uint64_t") || m.typename.equals("int64_t")) { 93 | warning('64 bit types for sizeof/countof members are not fully supported!\nThey throw a RuntimeException in case the value is larger than 2^63!', m, Structs4JavaDslPackage.Literals.INTEGER_MEMBER__TYPENAME) 94 | } 95 | } 96 | } 97 | } 98 | 99 | @Check 100 | def defaultValueInitializerListOfIntMemberDoesNotExceedArrayDimension(IntegerMember m) { 101 | if(m.array === null) { 102 | return 103 | } 104 | 105 | if(m.array.dimension == 0) { 106 | return 107 | } 108 | 109 | if(m.defaultValues === null) { 110 | return 111 | } 112 | 113 | if(m.array.dimension < m.defaultValues.items.size) { 114 | error("Can't fit default values (size=" + m.defaultValues.items.size + ") into fixed-sized array(size=" + m.array.dimension + ").", m, Structs4JavaDslPackage.Literals.INTEGER_MEMBER__DEFAULT_VALUES) 115 | } 116 | } 117 | 118 | @Check 119 | def defaultValueInitializerListOfIntMemberDoesNotExceedArrayDimension(FloatMember m) { 120 | if(m.array === null) { 121 | return 122 | } 123 | 124 | if(m.array.dimension == 0) { 125 | return 126 | } 127 | 128 | if(m.defaultValues === null) { 129 | return 130 | } 131 | 132 | if(m.array.dimension < m.defaultValues.items.size) { 133 | error("Can't fit default values (size=" + m.defaultValues.items.size + ") into fixed-sized array(size=" + m.array.dimension + ").", m, Structs4JavaDslPackage.Literals.FLOAT_MEMBER__DEFAULT_VALUES) 134 | } 135 | } 136 | 137 | @Check 138 | def defaultValueInitializerListOfIntMemberDoesNotExceedArrayDimension(StringMember m) { 139 | if(m.array === null) { 140 | return 141 | } 142 | 143 | if(m.array.dimension == 0) { 144 | return 145 | } 146 | 147 | if(m.defaultValue === null) { 148 | return 149 | } 150 | 151 | val encoding = if(m.encoding !== null) m.encoding else "UTF-8" 152 | var lenBytes = m.defaultValue.getBytes(encoding).length 153 | 154 | if(m.nullTerminated !== null) { 155 | lenBytes += "\u0000".getBytes(encoding).length 156 | } 157 | 158 | if(m.array.dimension < lenBytes) { 159 | error("Can't fit default value (size=" + lenBytes + ") into fixed-sized array(size=" + m.array.dimension + ").", m, Structs4JavaDslPackage.Literals.STRING_MEMBER__DEFAULT_VALUE) 160 | } 161 | } 162 | 163 | def getSizeOfFor(Member m) { 164 | val struct = m.eContainer as StructDeclaration; 165 | for(Member field : struct.members) { 166 | if(field instanceof IntegerMember) { 167 | if(field.sizeof.equals(m)) { 168 | return field 169 | } 170 | } 171 | } 172 | return null 173 | } 174 | 175 | def getCountOfFor(Member m) { 176 | val struct = m.eContainer as StructDeclaration; 177 | for(Member field : struct.members) { 178 | if(field instanceof IntegerMember) { 179 | if(field.countof.equals(m)) { 180 | return field 181 | } 182 | } 183 | } 184 | return null 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.github.marc-christian-schulze.structs4java 5 | build-all 6 | 1.0.54-SNAPSHOT 7 | pom 8 | 9 | https://github.com/marc-christian-schulze/structs4java 10 | 11 | 12 | Marc-Christian Schulze 13 | Marc.Christian.Schulze@gmail.com 14 | GitHub 15 | https://github.com/marc-christian-schulze 16 | 17 | 18 | 19 | 20 | The Apache License, Version 2.0 21 | http://www.apache.org/licenses/LICENSE-2.0.txt 22 | 23 | 24 | 25 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 26 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 27 | https://github.com/marc-christian-schulze/structs4java/tree/master 28 | 29 | 30 | 31 | org.structs4java.parent 32 | structs4java-with-dependencies 33 | structs4java-core 34 | structs4java-maven-plugin 35 | structs4java-maven-plugin-test 36 | examples 37 | 38 | 39 | -------------------------------------------------------------------------------- /structs4java-core/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.github.marc-christian-schulze.structs4java 5 | structs4java-core 6 | 1.0.54-SNAPSHOT 7 | jar 8 | 9 | 10 | UTF-8 11 | 2.28.0 12 | 11 13 | 11 14 | 15 | 16 | ${project.groupId}:${project.artifactId} 17 | Structs4Java is a code generator based on C/C++ structures. 18 | https://github.com/marc-christian-schulze/structs4java 19 | 20 | 21 | Marc-Christian Schulze 22 | Marc.Christian.Schulze@gmail.com 23 | GitHub 24 | https://github.com/marc-christian-schulze 25 | 26 | 27 | 28 | 29 | The Apache License, Version 2.0 30 | http://www.apache.org/licenses/LICENSE-2.0.txt 31 | 32 | 33 | 34 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 35 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 36 | https://github.com/marc-christian-schulze/structs4java/tree/master 37 | 38 | 39 | 40 | 41 | com.github.marc-christian-schulze.structs4java 42 | structs4java-with-dependencies 43 | ${project.version} 44 | 45 | 46 | org.eclipse.xtext 47 | org.eclipse.xtext 48 | ${xtext.version} 49 | 50 | 51 | org.eclipse.xtext 52 | org.eclipse.xtext.common.types 53 | ${xtext.version} 54 | 55 | 56 | 57 | org.eclipse.xtext 58 | org.eclipse.xtext.xbase 59 | ${xtext.version} 60 | 61 | 62 | 63 | org.eclipse.xtend 64 | org.eclipse.xtend.core 65 | ${xtext.version} 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.eclipse.xtext 73 | xtext-dev-bom 74 | ${xtext.version} 75 | pom 76 | import 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.apache.maven.plugins 85 | maven-source-plugin 86 | 3.0.1 87 | 88 | 89 | attach-sources 90 | 91 | jar 92 | 93 | 94 | 95 | 96 | 97 | org.apache.maven.plugins 98 | maven-javadoc-plugin 99 | 2.10.4 100 | 101 | 102 | attach-javadocs 103 | 104 | jar 105 | 106 | 107 | 8 108 | 109 | 110 | 111 | 112 | 113 | org.apache.maven.plugins 114 | maven-compiler-plugin 115 | 3.6.1 116 | 117 | ${maven.compiler.source} 118 | ${maven.compiler.target} 119 | 120 | 121 | 122 | org.apache.maven.plugins 123 | maven-shade-plugin 124 | 3.0.0 125 | 126 | true 127 | 128 | 129 | com.github.marc-christian-schulze.structs4java:* 130 | 131 | 132 | 133 | 134 | 135 | package 136 | 137 | shade 138 | 139 | 140 | 141 | 142 | 143 | org.apache.maven.plugins 144 | maven-jar-plugin 145 | 2.4 146 | 147 | 148 | 149 | true 150 | 151 | 152 | lib/ 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | release 163 | 164 | 165 | 166 | org.apache.maven.plugins 167 | maven-gpg-plugin 168 | 3.0.1 169 | 170 | 171 | sign-artifacts 172 | verify 173 | 174 | sign 175 | 176 | 177 | 178 | --pinentry-mode 179 | loopback 180 | 181 | 182 | 183 | 184 | 185 | 186 | org.sonatype.central 187 | central-publishing-maven-plugin 188 | 0.6.0 189 | true 190 | 191 | central 192 | true 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /structs4java-core/src/main/java/org/structs4java/MavenStructs4JavaDslRuntimeModule.java: -------------------------------------------------------------------------------- 1 | package org.structs4java; 2 | 3 | public class MavenStructs4JavaDslRuntimeModule extends Structs4JavaDslRuntimeModule { 4 | 5 | } -------------------------------------------------------------------------------- /structs4java-core/src/main/java/org/structs4java/MavenStructs4JavaDslStandaloneSetupGenerated.java: -------------------------------------------------------------------------------- 1 | package org.structs4java; 2 | 3 | import com.google.inject.Guice; 4 | import com.google.inject.Injector; 5 | 6 | public class MavenStructs4JavaDslStandaloneSetupGenerated extends Structs4JavaDslStandaloneSetupGenerated { 7 | 8 | @Override 9 | public Injector createInjector() { 10 | return Guice.createInjector(new MavenStructs4JavaDslRuntimeModule()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # Linux start script should use lf 5 | /gradlew text eol=lf 6 | 7 | # These are Windows script files and should use crlf 8 | *.bat text eol=crlf 9 | 10 | # Binary files should be left untouched 11 | *.jar binary 12 | 13 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/gradle.properties: -------------------------------------------------------------------------------- 1 | # This file was generated by the Gradle 'init' task. 2 | # https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties 3 | 4 | org.gradle.configuration-cache=true 5 | 6 | version=1.0.54-SNAPSHOT -------------------------------------------------------------------------------- /structs4java-gradle-plugin/gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | # This file was generated by the Gradle 'init' task. 2 | # https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format 3 | 4 | [versions] 5 | junit-jupiter = "5.11.1" 6 | 7 | [libraries] 8 | junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" } 9 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marc-christian-schulze/structs4java/d9b16a3143954306e95e157198fba9bb51c6b230/structs4java-gradle-plugin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /structs4java-gradle-plugin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | # SPDX-License-Identifier: Apache-2.0 19 | # 20 | 21 | ############################################################################## 22 | # 23 | # Gradle start up script for POSIX generated by Gradle. 24 | # 25 | # Important for running: 26 | # 27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 28 | # noncompliant, but you have some other compliant shell such as ksh or 29 | # bash, then to run this script, type that shell name before the whole 30 | # command line, like: 31 | # 32 | # ksh Gradle 33 | # 34 | # Busybox and similar reduced shells will NOT work, because this script 35 | # requires all of these POSIX shell features: 36 | # * functions; 37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 39 | # * compound commands having a testable exit status, especially «case»; 40 | # * various built-in commands including «command», «set», and «ulimit». 41 | # 42 | # Important for patching: 43 | # 44 | # (2) This script targets any POSIX shell, so it avoids extensions provided 45 | # by Bash, Ksh, etc; in particular arrays are avoided. 46 | # 47 | # The "traditional" practice of packing multiple parameters into a 48 | # space-separated string is a well documented source of bugs and security 49 | # problems, so this is (mostly) avoided, by progressively accumulating 50 | # options in "$@", and eventually passing that to Java. 51 | # 52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 54 | # see the in-line comments for details. 55 | # 56 | # There are tweaks for specific operating systems such as AIX, CygWin, 57 | # Darwin, MinGW, and NonStop. 58 | # 59 | # (3) This script is generated from the Groovy template 60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 61 | # within the Gradle project. 62 | # 63 | # You can find Gradle at https://github.com/gradle/gradle/. 64 | # 65 | ############################################################################## 66 | 67 | # Attempt to set APP_HOME 68 | 69 | # Resolve links: $0 may be a link 70 | app_path=$0 71 | 72 | # Need this for daisy-chained symlinks. 73 | while 74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 75 | [ -h "$app_path" ] 76 | do 77 | ls=$( ls -ld "$app_path" ) 78 | link=${ls#*' -> '} 79 | case $link in #( 80 | /*) app_path=$link ;; #( 81 | *) app_path=$APP_HOME$link ;; 82 | esac 83 | done 84 | 85 | # This is normally unused 86 | # shellcheck disable=SC2034 87 | APP_BASE_NAME=${0##*/} 88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | if ! command -v java >/dev/null 2>&1 137 | then 138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 139 | 140 | Please set the JAVA_HOME variable in your environment to match the 141 | location of your Java installation." 142 | fi 143 | fi 144 | 145 | # Increase the maximum file descriptors if we can. 146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 147 | case $MAX_FD in #( 148 | max*) 149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 150 | # shellcheck disable=SC2039,SC3045 151 | MAX_FD=$( ulimit -H -n ) || 152 | warn "Could not query maximum file descriptor limit" 153 | esac 154 | case $MAX_FD in #( 155 | '' | soft) :;; #( 156 | *) 157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 158 | # shellcheck disable=SC2039,SC3045 159 | ulimit -n "$MAX_FD" || 160 | warn "Could not set maximum file descriptor limit to $MAX_FD" 161 | esac 162 | fi 163 | 164 | # Collect all arguments for the java command, stacking in reverse order: 165 | # * args from the command line 166 | # * the main class name 167 | # * -classpath 168 | # * -D...appname settings 169 | # * --module-path (only if needed) 170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 171 | 172 | # For Cygwin or MSYS, switch paths to Windows format before running java 173 | if "$cygwin" || "$msys" ; then 174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 176 | 177 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 178 | 179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 180 | for arg do 181 | if 182 | case $arg in #( 183 | -*) false ;; # don't mess with options #( 184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 185 | [ -e "$t" ] ;; #( 186 | *) false ;; 187 | esac 188 | then 189 | arg=$( cygpath --path --ignore --mixed "$arg" ) 190 | fi 191 | # Roll the args list around exactly as many times as the number of 192 | # args, so each arg winds up back in the position where it started, but 193 | # possibly modified. 194 | # 195 | # NB: a `for` loop captures its iteration list before it begins, so 196 | # changing the positional parameters here affects neither the number of 197 | # iterations, nor the values presented in `arg`. 198 | shift # remove old arg 199 | set -- "$@" "$arg" # push replacement arg 200 | done 201 | fi 202 | 203 | 204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 206 | 207 | # Collect all arguments for the java command: 208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 209 | # and any embedded shellness will be escaped. 210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 211 | # treated as '${Hostname}' itself on the command line. 212 | 213 | set -- \ 214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 215 | -classpath "$CLASSPATH" \ 216 | org.gradle.wrapper.GradleWrapperMain \ 217 | "$@" 218 | 219 | # Stop when "xargs" is not available. 220 | if ! command -v xargs >/dev/null 2>&1 221 | then 222 | die "xargs is not available" 223 | fi 224 | 225 | # Use "xargs" to parse quoted args. 226 | # 227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 228 | # 229 | # In Bash we could simply go: 230 | # 231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 232 | # set -- "${ARGS[@]}" "$@" 233 | # 234 | # but POSIX shell has neither arrays nor command substitution, so instead we 235 | # post-process each arg (as a line of input to sed) to backslash-escape any 236 | # character that might be a shell metacharacter, then use eval to reverse 237 | # that process (while maintaining the separation between arguments), and wrap 238 | # the whole thing up as a single "set" statement. 239 | # 240 | # This will of course break if any of these variables contains a newline or 241 | # an unmatched quote. 242 | # 243 | 244 | eval "set -- $( 245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 246 | xargs -n1 | 247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 248 | tr '\n' ' ' 249 | )" '"$@"' 250 | 251 | exec "$JAVACMD" "$@" 252 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | @rem SPDX-License-Identifier: Apache-2.0 17 | @rem 18 | 19 | @if "%DEBUG%"=="" @echo off 20 | @rem ########################################################################## 21 | @rem 22 | @rem Gradle startup script for Windows 23 | @rem 24 | @rem ########################################################################## 25 | 26 | @rem Set local scope for the variables with windows NT shell 27 | if "%OS%"=="Windows_NT" setlocal 28 | 29 | set DIRNAME=%~dp0 30 | if "%DIRNAME%"=="" set DIRNAME=. 31 | @rem This is normally unused 32 | set APP_BASE_NAME=%~n0 33 | set APP_HOME=%DIRNAME% 34 | 35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 37 | 38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 40 | 41 | @rem Find java.exe 42 | if defined JAVA_HOME goto findJavaFromJavaHome 43 | 44 | set JAVA_EXE=java.exe 45 | %JAVA_EXE% -version >NUL 2>&1 46 | if %ERRORLEVEL% equ 0 goto execute 47 | 48 | echo. 1>&2 49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 50 | echo. 1>&2 51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 52 | echo location of your Java installation. 1>&2 53 | 54 | goto fail 55 | 56 | :findJavaFromJavaHome 57 | set JAVA_HOME=%JAVA_HOME:"=% 58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 59 | 60 | if exist "%JAVA_EXE%" goto execute 61 | 62 | echo. 1>&2 63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 64 | echo. 1>&2 65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 66 | echo location of your Java installation. 1>&2 67 | 68 | goto fail 69 | 70 | :execute 71 | @rem Setup the command line 72 | 73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 74 | 75 | 76 | @rem Execute Gradle 77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 78 | 79 | :end 80 | @rem End local scope for the variables with windows NT shell 81 | if %ERRORLEVEL% equ 0 goto mainEnd 82 | 83 | :fail 84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 85 | rem the _cmd.exe /c_ return code! 86 | set EXIT_CODE=%ERRORLEVEL% 87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 89 | exit /b %EXIT_CODE% 90 | 91 | :mainEnd 92 | if "%OS%"=="Windows_NT" endlocal 93 | 94 | :omega 95 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/plugin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This generated file contains a sample Gradle plugin project to get you started. 5 | * For more details on writing Custom Plugins, please refer to https://docs.gradle.org/8.12/userguide/custom_plugins.html in the Gradle documentation. 6 | */ 7 | 8 | import org.gradle.api.tasks.testing.logging.TestExceptionFormat 9 | 10 | plugins { 11 | // Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins 12 | `java-gradle-plugin` 13 | 14 | id("com.gradle.plugin-publish") version "1.3.0" 15 | } 16 | 17 | repositories { 18 | mavenLocal() 19 | // Use Maven Central for resolving dependencies. 20 | mavenCentral() 21 | 22 | maven(url = "../../.m2") 23 | google() 24 | } 25 | 26 | dependencies { 27 | // Use JUnit Jupiter for testing. 28 | testImplementation(libs.junit.jupiter) 29 | 30 | testRuntimeOnly("org.junit.platform:junit-platform-launcher") 31 | 32 | implementation("com.github.marc-christian-schulze.structs4java:structs4java-core:${project.version}") 33 | 34 | implementation("com.android.tools.build:gradle-api:8.1.2") 35 | } 36 | 37 | gradlePlugin { 38 | // Define the plugin 39 | val structs4java by plugins.creating { 40 | group = "io.github.marc-christian-schulze.structs4java" 41 | id = "io.github.marc-christian-schulze.structs4java.structs4java-gradle-plugin" 42 | implementationClass = "org.structs4java.Structs4javaGradlePlugin" 43 | website.set("https://github.com/marc-christian-schulze/structs4java") 44 | vcsUrl.set("https://github.com/marc-christian-schulze/structs4java.git") 45 | displayName = "Structs4Java Gradle Plugin" 46 | description = "Structs4Java is a code generator based on C/C++ structures." 47 | tags = listOf("generator", "structs") 48 | } 49 | } 50 | 51 | // Add a source set for the functional test suite 52 | val functionalTestSourceSet = sourceSets.create("functionalTest") { 53 | } 54 | 55 | configurations["functionalTestImplementation"].extendsFrom(configurations["testImplementation"]) 56 | configurations["functionalTestRuntimeOnly"].extendsFrom(configurations["testRuntimeOnly"]) 57 | 58 | // Add a task to run the functional tests 59 | val functionalTest by tasks.registering(Test::class) { 60 | testClassesDirs = functionalTestSourceSet.output.classesDirs 61 | classpath = functionalTestSourceSet.runtimeClasspath 62 | useJUnitPlatform() 63 | testLogging.events("failed") 64 | testLogging.exceptionFormat = TestExceptionFormat.FULL 65 | testLogging.showExceptions = true 66 | testLogging.showCauses = true 67 | } 68 | 69 | gradlePlugin.testSourceSets.add(functionalTestSourceSet) 70 | 71 | tasks.named("check") { 72 | // Run the functional tests as part of `check` 73 | dependsOn(functionalTest) 74 | } 75 | 76 | tasks.named("test") { 77 | // Use JUnit Jupiter for unit tests. 78 | useJUnitPlatform() 79 | } 80 | 81 | tasks.withType { 82 | options.release = 17 83 | } 84 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/plugin/src/functionalTest/java/org/structs4java/Structs4javaGradlePluginFunctionalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file was generated by the Gradle 'init' task 3 | */ 4 | package org.structs4java; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.io.Writer; 9 | import java.io.FileWriter; 10 | import java.nio.file.Files; 11 | import org.gradle.testkit.runner.GradleRunner; 12 | import org.gradle.testkit.runner.BuildResult; 13 | import org.junit.jupiter.api.Test; 14 | import org.junit.jupiter.api.io.TempDir; 15 | import static org.junit.jupiter.api.Assertions.*; 16 | 17 | /** 18 | * A simple functional test for the 'com.github.marc-christian-schulze.structs4java' plugin. 19 | */ 20 | class Structs4javaGradlePluginFunctionalTest { 21 | @TempDir(cleanup = org.junit.jupiter.api.io.CleanupMode.NEVER) 22 | File projectDir; 23 | 24 | private File getBuildFile() { 25 | return new File(projectDir, "build.gradle"); 26 | } 27 | 28 | private File getSettingsFile() { 29 | return new File(projectDir, "settings.gradle"); 30 | } 31 | 32 | private File getStructSrcDirectory() { 33 | File dir = new File(projectDir, "src/main/structs"); 34 | dir.mkdirs(); 35 | return dir; 36 | } 37 | 38 | private File getJavaSrcDirectory() { 39 | File dir = new File(projectDir, "src/main/java"); 40 | dir.mkdirs(); 41 | return dir; 42 | } 43 | 44 | private File getStructsFile() { 45 | return new File(getStructSrcDirectory(), "example.structs"); 46 | } 47 | 48 | private File getInterfaceFile() { 49 | new File(getJavaSrcDirectory(), "something").mkdirs(); 50 | return new File(getJavaSrcDirectory(), "something/SomeInterface.java"); 51 | } 52 | 53 | @Test void canRunTask() throws IOException { 54 | writeString(getSettingsFile(), ""); 55 | writeString(getBuildFile(), """ 56 | plugins { 57 | id('java') 58 | id('io.github.marc-christian-schulze.structs4java.structs4java-gradle-plugin') 59 | } 60 | """); 61 | writeString(getInterfaceFile(), """ 62 | package something; 63 | 64 | interface SomeInterface { 65 | } 66 | """); 67 | writeString(getStructsFile(), """ 68 | package something; 69 | 70 | struct Example implements SomeInterface { 71 | uint32_t anInt; 72 | } 73 | """); 74 | 75 | // Run the build 76 | GradleRunner runner = GradleRunner.create(); 77 | runner.forwardOutput(); 78 | runner.withPluginClasspath(); 79 | runner.withArguments("compileJava", "--info"); 80 | runner.withProjectDir(projectDir); 81 | BuildResult result = runner.build(); 82 | 83 | // Verify the result 84 | assertTrue(result.getOutput().contains("loading structs file")); 85 | assertTrue(result.getOutput().contains("/example.structs")); 86 | assertTrue(new File(projectDir + "/build/generated/main/java/something/Example.java").isFile()); 87 | assertTrue(new File(projectDir + "/build/classes/java/main/something/Example.class").isFile()); 88 | } 89 | 90 | private void writeString(File file, String string) throws IOException { 91 | try (Writer writer = new FileWriter(file)) { 92 | writer.write(string); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/plugin/src/main/java/org/structs4java/CompileStructsTask.java: -------------------------------------------------------------------------------- 1 | package org.structs4java; 2 | 3 | import org.gradle.api.DefaultTask; 4 | import org.gradle.api.tasks.TaskAction; 5 | import org.gradle.api.tasks.InputFiles; 6 | import org.gradle.api.tasks.Input; 7 | import org.gradle.api.provider.Property; 8 | import org.gradle.api.tasks.OutputDirectory; 9 | import org.gradle.api.file.ConfigurableFileTree; 10 | import org.gradle.api.file.DirectoryProperty; 11 | import org.gradle.api.GradleException; 12 | import org.structs4java.StructsBatchCompiler; 13 | 14 | import java.io.File; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | public class CompileStructsTask extends DefaultTask { 19 | 20 | ConfigurableFileTree structFiles = getProject().getObjects().fileTree(); 21 | DirectoryProperty outputDirectory = getProject().getObjects().directoryProperty(); 22 | Property fileEncoding = getProject().getObjects().property(String.class); 23 | Property source = getProject().getObjects().property(String.class); 24 | Property target = getProject().getObjects().property(String.class); 25 | Property classPath = getProject().getObjects().property(String.class); 26 | Property sourcePath = getProject().getObjects().property(String.class); 27 | Property writeTraceFiles = getProject().getObjects().property(Boolean.class); 28 | Property deleteTempDirectory = getProject().getObjects().property(Boolean.class); 29 | 30 | @Input 31 | public Property getFileEncoding() { return fileEncoding; } 32 | 33 | @Input 34 | public Property getSource() { return source; } 35 | 36 | @Input 37 | public Property getTarget() { return target; } 38 | 39 | @Input 40 | public Property getClassPath() { return classPath; } 41 | 42 | @Input 43 | public Property getSourcePath() { return sourcePath; } 44 | 45 | @Input 46 | public Property getWriteTraceFiles() { return writeTraceFiles; } 47 | 48 | @Input 49 | public Property getDeleteTempDirectory() { return deleteTempDirectory; } 50 | 51 | @InputFiles 52 | public ConfigurableFileTree getStructFiles() { // ConfigurableFileTree 53 | return structFiles; 54 | } 55 | 56 | @OutputDirectory 57 | public DirectoryProperty getOutputDirectory() { 58 | return outputDirectory; 59 | } 60 | 61 | @TaskAction 62 | public void compileStructs() { 63 | StructsBatchCompiler compiler = new StructsBatchCompiler(); 64 | 65 | getLogger().debug("deleteTempDirectory = " + getDeleteTempDirectory().get()); 66 | compiler.setDeleteTempDirectory(getDeleteTempDirectory().get()); 67 | getLogger().debug("classPath = " + classPath.get()); 68 | compiler.setClassPath(classPath.get()); 69 | compiler.setBootClassPath(""); 70 | getLogger().debug("sourcePath = " + sourcePath.get()); 71 | compiler.setSourcePath(sourcePath.get()); 72 | getLogger().debug("outputDirectory = " + getOutputDirectory().getAsFile().get().toString()); 73 | compiler.setOutputPath(getOutputDirectory().getAsFile().get().toString()); 74 | getLogger().debug("fileEncoding = " + fileEncoding.get()); 75 | compiler.setFileEncoding(fileEncoding.get()); 76 | getLogger().debug("structFiles = " + structFiles.getFiles()); 77 | compiler.setStructFiles(new ArrayList<>(structFiles.getFiles())); 78 | getLogger().debug("writeTraceFiles = " + getWriteTraceFiles().get()); 79 | compiler.setWriteTraceFiles(getWriteTraceFiles().get()); 80 | getLogger().debug("source = " + getSource().get()); 81 | compiler.setSourceVersion(getSource().get()); 82 | getLogger().debug("target = " + getTarget().get()); 83 | compiler.setTargetVersion(getTarget().get()); 84 | 85 | if (!compiler.compile()) { 86 | throw new GradleException("Failed to compile struct files!"); 87 | } 88 | 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/plugin/src/main/java/org/structs4java/Structs4javaGradlePlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file was generated by the Gradle 'init' task 3 | */ 4 | package org.structs4java; 5 | 6 | import org.gradle.api.Project; 7 | import org.gradle.api.Plugin; 8 | import org.gradle.api.Task; 9 | import org.gradle.api.tasks.TaskProvider; 10 | import org.gradle.api.tasks.SourceSet; 11 | import org.gradle.api.plugins.JavaPlugin; 12 | import org.gradle.api.tasks.compile.JavaCompile; 13 | import org.gradle.api.plugins.JavaPluginExtension; 14 | 15 | import java.util.stream.Collectors; 16 | import java.io.File; 17 | 18 | import com.android.build.gradle.AppPlugin; 19 | import com.android.build.api.variant.ApplicationAndroidComponentsExtension; 20 | 21 | 22 | /** 23 | * A simple 'hello world' plugin. 24 | */ 25 | public class Structs4javaGradlePlugin implements Plugin { 26 | public void apply(Project project) { 27 | 28 | TaskProvider taskProvider = project.getTasks().register("compileStructs", CompileStructsTask.class); 29 | 30 | taskProvider.configure(compileStructs -> { 31 | compileStructs.outputDirectory.value(project.getLayout().getBuildDirectory().dir("generated/main/java").get()); 32 | compileStructs.structFiles.setDir(project.getLayout().getProjectDirectory().dir("src/main/structs").getAsFile().toString()).include("**/*.structs"); 33 | compileStructs.fileEncoding.set("UTF-8"); 34 | compileStructs.source.set("11"); 35 | compileStructs.target.set("11"); 36 | compileStructs.deleteTempDirectory.set(false); 37 | compileStructs.writeTraceFiles.set(false); 38 | }); 39 | 40 | if(isAndroidProject(project)) { 41 | project.getPlugins().withType(AppPlugin.class).configureEach(plugin -> { 42 | ApplicationAndroidComponentsExtension androidComponents = project.getExtensions().getByType(ApplicationAndroidComponentsExtension.class); 43 | androidComponents.onVariants(androidComponents.selector().all(), variant -> { 44 | variant.getSources().getJava().addGeneratedSourceDirectory(taskProvider, CompileStructsTask::getOutputDirectory); 45 | }); 46 | }); 47 | 48 | } else { 49 | 50 | project.getPlugins().withType(JavaPlugin.class, javaPlugin -> { 51 | JavaPluginExtension javaExtension = project.getExtensions().getByType(JavaPluginExtension.class); 52 | SourceSet mainSourceSet = javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); 53 | mainSourceSet.getJava().srcDir(taskProvider.get().getOutputDirectory()); 54 | }); 55 | 56 | project.afterEvaluate(p -> { 57 | project.getTasks().withType(JavaCompile.class).configureEach(javaCompile -> { 58 | javaCompile.dependsOn("compileStructs"); 59 | taskProvider.get().classPath.set(javaCompile.getClasspath().getAsPath()); 60 | taskProvider.get().sourcePath.set(javaCompile.getSource().getFiles().stream() 61 | .map(f -> f.getParent()) 62 | .map(Object::toString) 63 | .distinct() 64 | .collect(Collectors.joining(File.pathSeparator)) 65 | ); 66 | }); 67 | 68 | }); 69 | } 70 | } 71 | 72 | private static boolean isAndroidProject(Project project) { 73 | return project.getPlugins().withType(AppPlugin.class).size() > 0; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/plugin/src/test/java/org/structs4java/Structs4javaGradlePluginTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This source file was generated by the Gradle 'init' task 3 | */ 4 | package org.structs4java; 5 | 6 | import org.gradle.testfixtures.ProjectBuilder; 7 | import org.gradle.api.Project; 8 | import org.junit.jupiter.api.Test; 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | /** 12 | * A simple unit test for the 'com.github.marc-christian-schulze.structs4java' plugin. 13 | */ 14 | class Structs4javaGradlePluginTest { 15 | @Test void pluginRegistersATask() { 16 | // Create a test project and apply the plugin 17 | Project project = ProjectBuilder.builder().build(); 18 | project.getPlugins().apply("io.github.marc-christian-schulze.structs4java.structs4java-gradle-plugin"); 19 | 20 | // Verify the result 21 | assertNotNull(project.getTasks().findByName("compileStructs")); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /structs4java-gradle-plugin/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.12/userguide/multi_project_builds.html in the Gradle documentation. 6 | */ 7 | 8 | rootProject.name = "structs4java-gradle-plugin" 9 | include("plugin") 10 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.github.marc-christian-schulze.structs4java 5 | structs4java-maven-plugin-test 6 | 1.0.54-SNAPSHOT 7 | 8 | 9 | UTF-8 10 | 17 11 | 17 12 | 13 | 14 | ${project.groupId}:${project.artifactId} 15 | Structs4Java is a code generator based on C/C++ structures. 16 | https://github.com/marc-christian-schulze/structs4java 17 | 18 | 19 | Marc-Christian Schulze 20 | Marc.Christian.Schulze@gmail.com 21 | GitHub 22 | https://github.com/marc-christian-schulze 23 | 24 | 25 | 26 | 27 | The Apache License, Version 2.0 28 | http://www.apache.org/licenses/LICENSE-2.0.txt 29 | 30 | 31 | 32 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 33 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 34 | https://github.com/marc-christian-schulze/structs4java/tree/master 35 | 36 | 37 | 38 | 39 | 40 | org.apache.maven.plugins 41 | maven-compiler-plugin 42 | 3.8.1 43 | 44 | ${maven.compiler.source} 45 | ${maven.compiler.target} 46 | 47 | 48 | 49 | com.github.marc-christian-schulze.structs4java 50 | structs4java-maven-plugin 51 | ${project.version} 52 | 53 | 54 | compile-structs 55 | 56 | compile 57 | 58 | 59 | 60 | 61 | ${maven.compiler.source} 62 | ${maven.compiler.target} 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | junit 71 | junit 72 | 4.13.2 73 | test 74 | 75 | 76 | com.google.guava 77 | guava 78 | 33.3.1-jre 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/java/org/structs4java/example/tests/InterfaceA.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | public interface InterfaceA { 4 | 5 | public long getA(); 6 | } 7 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/java/org/structs4java/example/tests/InterfaceB.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | public interface InterfaceB { 4 | 5 | public long getB(); 6 | } 7 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/Bitfields.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | enum MyEnum : uint8_t { 4 | A = 5, 5 | B = 7, 6 | C = 1 7 | } 8 | 9 | struct StructWithBitfields { 10 | 11 | bitfield uint8_t { 12 | uint8_t number : 3; 13 | boolean flag1 : 1; 14 | boolean flag2 : 1; 15 | int32_t number2 : 3; 16 | } 17 | 18 | // endianess dependent bitfield 19 | bitfield int32_t { 20 | uint8_t highByte : 8; 21 | int16_t middleBytes : 16; 22 | MyEnum lowByte : 8; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/CopyConstructorCases.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | enum AnyEnum : uint8_t { 4 | A = 0, 5 | B = 1 6 | } 7 | 8 | struct AnyStruct { 9 | int32_t i; 10 | } 11 | 12 | struct CopyConstructorCases { 13 | int8_t signed8; 14 | uint8_t unsigned8; 15 | int16_t signed16; 16 | uint16_t unsigned16; 17 | int32_t signed32; 18 | uint32_t unsigned32; 19 | int64_t signed64; 20 | uint64_t unsigned64; 21 | float f; 22 | double d; 23 | char str[10]; 24 | AnyEnum e; 25 | AnyStruct s; 26 | 27 | int8_t signed8Array[5]; 28 | uint8_t unsigned8Array[5]; 29 | int16_t signed16Array[5]; 30 | uint16_t unsigned16Array[5]; 31 | int32_t signed32Array[5]; 32 | uint32_t unsigned32Array[5]; 33 | int64_t signed64Array[5]; 34 | uint64_t unsigned64Array[5]; 35 | float fArray[5]; 36 | double dArray[5]; 37 | AnyEnum eArray[5]; 38 | AnyStruct sArray[5]; 39 | } 40 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/EndianessTest.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.bugs.endianess; 2 | 3 | struct Outer { 4 | uint8_t length sizeof(inner); 5 | uint16_t word; 6 | Inner inner; 7 | } 8 | 9 | struct Inner { 10 | uint16_t word; 11 | } 12 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/EnumWithLargeNumbers.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | enum LargeNumberEnum32 : uint32_t { 4 | SMALL = 0x40000000, 5 | LARGE = 0x80000000 6 | } 7 | 8 | enum LargeNumberEnum64 : uint64_t { 9 | SMALL = 0x40000000, 10 | LARGE = 0x80000000 11 | VERY_LARGE = 0x7FFFFFFFFFFFFFFF 12 | } 13 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/Example1.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example1; 2 | 3 | struct SimpleStructure { 4 | int16_t word1; 5 | uint16_t word2; 6 | uint32_t dword3; 7 | char someString[32]; 8 | SimpleEnum enumValue; 9 | } 10 | 11 | enum SimpleEnum : uint16_t { 12 | FirstItem = 0xCAFE, 13 | SecondItem = 42 14 | } 15 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/Example2.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example2; 2 | 3 | import org.structs4java.example1.SimpleStructure; 4 | 5 | struct AdvancedStructure { 6 | float someFloat_; 7 | SimpleStructure anArray[5]; 8 | } 9 | 10 | struct StructureWithByteArray { 11 | uint8_t someByteArray[64]; 12 | } 13 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/Example3.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example3; 2 | 3 | struct NullTerminatedString { 4 | char value[]; 5 | } 6 | 7 | struct BString { 8 | uint32_t size sizeof(value); 9 | char value[] null-terminated; 10 | } 11 | 12 | struct DynamicStruct { 13 | int16_t size sizeof(this); 14 | int32_t optionalWhatever; 15 | OptionalPart optionalFields; 16 | } 17 | 18 | struct OptionalPart { 19 | uint16_t x; 20 | uint16_t y; 21 | uint16_t z; 22 | } 23 | 24 | struct OptionalPart2 { 25 | int32_t mandatory; 26 | OptionalPart any; 27 | } 28 | 29 | struct DynamicStructHavingPartialNestedObject { 30 | int16_t size sizeof(optionalFields); 31 | OptionalPart2 optionalFields; 32 | } 33 | 34 | struct ListOfIntegers { 35 | int16_t array[10]; 36 | } -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/Example4.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example4; 2 | 3 | struct SimpleGreedy { 4 | uint8_t first; 5 | uint8_t rest[]; 6 | } 7 | 8 | struct NonGreedy { 9 | uint8_t veryFirst sizeof(greedy); 10 | SimpleGreedy greedy; 11 | } 12 | 13 | struct SelfSizedGreedy { 14 | uint8_t selfSize sizeof(this); 15 | uint8_t rest[]; 16 | } 17 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/FixSizedStringWithCustomFiller.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.test; 2 | 3 | struct FixSizedStringWithCustomFiller { 4 | char value[4] filler(0x20); 5 | } 6 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/GreedyTest.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | struct InnerGreedy { 4 | uint16_t size sizeof(content); 5 | uint8_t content[]; 6 | } 7 | 8 | struct OuterGreedy { 9 | uint16_t size sizeof(content); 10 | InnerGreedy inner; 11 | uint8_t content[]; 12 | } 13 | 14 | 15 | struct MultipleGreedy { 16 | uint8_t sizeOne sizeof(first); 17 | uint8_t first[]; 18 | uint8_t sizeTwo sizeof(second); 19 | uint8_t second[]; 20 | } 21 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/ImplicitImportOfSameNamespace.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example1; 2 | 3 | struct ImportingStruct { 4 | SimpleStructure structure; 5 | } 6 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/NotNullTerminatedVarSizeString.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.test; 2 | 3 | struct DynamicString { 4 | uint32_t length sizeof(value); 5 | char value[]; 6 | } 7 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/PadUsingCustomByte.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.test; 2 | 3 | struct PaddedWithCustomByte { 4 | uint8_t value1 padding(4, using = 0xFF); 5 | uint16_t value2 padding(4, using = 0xFF); 6 | uint32_t value3 padding(8, using = 0xFF); 7 | uint64_t value4 padding(10, using = 0xFF); 8 | char value5[4] padding(5, using = 0xFF); 9 | float value6 padding(5, using = 0xFF); 10 | double value7 padding(9, using = 0xFF); 11 | } 12 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/PaddingTest.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | struct PaddedByteMember { 4 | uint8_t paddedByte padding(4); 5 | uint8_t followingByte; 6 | } 7 | 8 | struct PaddedWordMember { 9 | uint16_t paddedWord padding(4); 10 | uint8_t followingByte; 11 | } 12 | 13 | struct PaddedDWordMember { 14 | uint32_t paddedDWord padding(4); 15 | uint8_t followingByte; 16 | } 17 | 18 | struct PaddedDWordMemberAt8Bytes { 19 | uint32_t paddedDWord padding(8); 20 | uint8_t followingByte; 21 | } 22 | 23 | struct PaddedFloatMember { 24 | float paddedFloat padding(8); 25 | uint8_t followingByte; 26 | } 27 | 28 | struct PaddedDynamicByteArray { 29 | uint8_t size sizeof(array); 30 | uint8_t array[] padding(4); 31 | uint8_t followingByte; 32 | } -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/SizeOfArray.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests.sizeofarray; 2 | 3 | struct Outer { 4 | uint8_t length sizeof(fields); 5 | Inner fields[]; 6 | } 7 | 8 | struct Inner { 9 | uint8_t length sizeof(data); 10 | uint8_t data[]; 11 | } 12 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/StructWith64BitSizeType.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | struct StructWith64BitSizeType 4 | { 5 | uint64_t length sizeof(content); 6 | uint8_t content[]; 7 | } 8 | 9 | struct StructWith64BitSelfSizeType 10 | { 11 | uint64_t length sizeof(this); 12 | uint8_t content[]; 13 | } 14 | 15 | struct StructWith64BitCountType 16 | { 17 | uint64_t length countof(content); 18 | uint8_t content[]; 19 | } 20 | 21 | struct Dummy 22 | { 23 | char dummy[10]; 24 | } 25 | 26 | struct DummyStructWith64BitSizeType 27 | { 28 | uint64_t length sizeof(content); 29 | Dummy content; 30 | } 31 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/StructWithInterfaces.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | struct OneInterface implements InterfaceA { 4 | uint32_t a; 5 | } 6 | 7 | struct BothInterfaces implements InterfaceA, InterfaceB { 8 | uint32_t a; 9 | uint32_t b; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/WriteStringBug.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.test; 2 | 3 | // 4 | // generated broken code: 5 | // 6 | // private void writeName(java.nio.ByteBuffer buf) throws java.io.IOException { 7 | // try { 8 | // int memberBegin = buf.position(); 9 | // byte[] encoded = getName().getBytes("UTF-8"); 10 | // buf.put(encoded); 11 | // int bytesOverlap = ((buf.position() - beginMember) % 4); // BUG: should be memberBegin 12 | // if(bytesOverlap > 0) { 13 | // for(int i = 0; i < 4 - bytesOverlap; ++i) { 14 | // buf.put((byte)0); 15 | // } 16 | // } 17 | // } catch(java.io.UnsupportedEncodingException e) { 18 | // throw new java.io.IOException(e); 19 | // } 20 | // } 21 | // 22 | struct WriteStringBugStruct 23 | { 24 | uint32_t lengthName sizeof(name); 25 | char name[] padding(4); 26 | } 27 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/bugs.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.bugs; 2 | 3 | struct SignessBug { 4 | int32_t signed32; 5 | uint32_t unsigned32; 6 | int16_t signed16; 7 | uint16_t unsigned16; 8 | int8_t signed8; 9 | uint8_t unsigned8; 10 | } 11 | 12 | struct Element { 13 | int16_t value; 14 | } 15 | 16 | struct CountOfBug { 17 | uint8_t num countof(elements); 18 | Element elements[]; 19 | } 20 | 21 | 22 | struct Element2 { 23 | int16_t value; 24 | char name[]; 25 | } 26 | 27 | struct CountOfBug2 { 28 | uint8_t num countof(elements); 29 | Element2 elements[]; 30 | } 31 | 32 | struct FixedSizeByteBuffer { 33 | // due to a defect, if the buffer is not exactly 8 bytes when written 34 | uint8_t fixed_size_buffer[8]; 35 | // the following test field will be at a different location in the binary stream 36 | char test[4]; 37 | } -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/constants.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests.constants; 2 | 3 | struct StructWithPrimitiveConstants { 4 | int8_t a const = 1; 5 | uint8_t b const = 2; 6 | int16_t c const = 3; 7 | uint16_t d const = 4; 8 | int32_t e const = 5; 9 | uint32_t f const = 6; 10 | int64_t g const = 7; 11 | uint64_t h const = 8; 12 | float i const = 1.0; 13 | double j const = 2.0; 14 | } 15 | 16 | struct StructWithArrayConstants { 17 | int8_t a[1] const = { 1 }; 18 | uint8_t b[1] const = { 2 }; 19 | int16_t c[1] const = { 3 }; 20 | uint16_t d[1] const = { 4 }; 21 | int32_t e[1] const = { 5 }; 22 | uint32_t f[1] const = { 6 }; 23 | int64_t g[1] const = { 7 }; 24 | uint64_t h[1] const = { 8 }; 25 | float i[1] const = { 1.0 }; 26 | double j[1] const = { 2.0 }; 27 | } 28 | 29 | struct StructWithStringConstant { 30 | char str[4] const = "test"; 31 | } 32 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/default-values.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests.defaultvalues; 2 | 3 | struct StructWithIntegerDefaultValue { 4 | uint8_t int8 = 1; 5 | uint16_t int16 = 2; 6 | uint32_t int32 = 3; 7 | uint64_t int64 = 4; 8 | } 9 | 10 | struct StructWithFloatDefaultValue { 11 | float f = 1.0; 12 | double d = 2.0; 13 | } 14 | 15 | struct StructWithStringDefaultValue { 16 | char str[] = "default"; 17 | } 18 | 19 | struct StructWithArrayDefaultValue { 20 | uint8_t int8[3] = { 1, 0x20, 3 }; 21 | uint16_t int16[3] = { 4, 5, 6 }; 22 | uint32_t int32[3] = { 7, 8, 9 }; 23 | uint64_t int64[3] = { 0x10, 0x11, 0x12 }; 24 | float f[3] = { 1.0, 2.0, 3.0 }; 25 | double d[3] = { 4.0, 5.0, 6.0 }; 26 | } 27 | 28 | enum Int8Enum : uint8_t { 29 | A = 0x01, 30 | B = 0x02, 31 | C = 0x03 32 | } 33 | 34 | struct StructWithBitfield { 35 | bitfield uint16_t { 36 | boolean b : 1; 37 | uint8_t int8 : 2; 38 | uint16_t int16 : 2; 39 | uint32_t int32 : 2; 40 | uint64_t int64 : 2; 41 | Int8Enum int8Enum : 7; 42 | } 43 | } 44 | 45 | struct StructWithEnum { 46 | Int8Enum int8Enum = Int8Enum.B; 47 | } 48 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/default_package.structs: -------------------------------------------------------------------------------- 1 | // default package 2 | 3 | struct DidNotCompileInThePast { 4 | 5 | } 6 | 7 | enum DidNotCompileEither : uint16_t { 8 | A = 42 9 | } -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/main/structs/null-safety.structs: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests.nullsafety; 2 | 3 | struct StructWithByteBuffer { 4 | uint8_t buffer[10]; 5 | } 6 | 7 | struct StructWithInt32Array { 8 | int32_t array[10]; 9 | } 10 | 11 | struct StructWithStructArray { 12 | StructWithInt32Array array[10]; 13 | } -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/test/java/org/structs4java/example/tests/AbstractTest.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.util.ArrayList; 5 | 6 | import org.junit.Before; 7 | import org.junit.After; 8 | import org.junit.Assert; 9 | import org.structs4java.example1.SimpleEnum; 10 | import org.structs4java.example1.SimpleStructure; 11 | import org.structs4java.example2.AdvancedStructure; 12 | 13 | public class AbstractTest { 14 | 15 | private static final int BUFFER_SIZE = 256; 16 | protected ByteBuffer buffer; 17 | 18 | @Before 19 | public void before() { 20 | buffer = ByteBuffer.allocate(BUFFER_SIZE); 21 | for(int i = 0; i < BUFFER_SIZE; ++i) { 22 | buffer.put((byte)0xFF); 23 | } 24 | buffer.position(0); 25 | 26 | System.out.println("------------------------- NEW TESTCASE ------------------------------"); 27 | System.out.println("Buffer before:"); 28 | dumpBuffer(); 29 | } 30 | 31 | @After 32 | public void after() { 33 | System.out.println("Buffer after:"); 34 | dumpBuffer(); 35 | } 36 | 37 | public void dumpBuffer() { 38 | dumpBuffer(buffer); 39 | } 40 | 41 | private void dumpBuffer(ByteBuffer buf) { 42 | for(int i = 0; i < buf.limit(); ++i) { 43 | System.out.print(String.format("%02X ", buf.get(i))); 44 | if(i % 32 == 31) { 45 | System.out.println(); 46 | } 47 | } 48 | System.out.println(); 49 | } 50 | 51 | public SimpleStructure createSimpleStruct() { 52 | SimpleStructure struct = new SimpleStructure(); 53 | struct.setWord1(-478); 54 | struct.setWord2(0x6699); 55 | struct.setDword3(0x11223344); 56 | struct.setEnumValue(SimpleEnum.SecondItem); 57 | struct.setSomeString("foobar"); 58 | return struct; 59 | } 60 | 61 | public AdvancedStructure createAdvancedStruct() { 62 | ArrayList structs = new ArrayList(); 63 | for(int i = 0; i < 5; ++i) { 64 | structs.add(createSimpleStruct()); 65 | } 66 | AdvancedStructure expected = new AdvancedStructure(); 67 | expected.setSomeFloat_(1.234f); 68 | expected.setAnArray(structs); 69 | return expected; 70 | } 71 | 72 | protected void assertEqualBuffers(ByteBuffer a, ByteBuffer b) { 73 | a.position(0); 74 | b.position(0); 75 | if(!a.equals(b)) { 76 | System.out.println("Expected:"); 77 | dumpBuffer(a); 78 | System.out.println("Actual:"); 79 | dumpBuffer(b); 80 | Assert.fail("ByteBuffers are not equal!"); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/test/java/org/structs4java/example/tests/ConstantTest.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | import org.junit.Test; 4 | import org.structs4java.example.tests.constants.StructWithArrayConstants; 5 | import org.structs4java.example.tests.constants.StructWithPrimitiveConstants; 6 | import org.structs4java.example.tests.constants.StructWithStringConstant; 7 | 8 | import java.io.IOException; 9 | import java.nio.ByteBuffer; 10 | import java.nio.ByteOrder; 11 | 12 | public class ConstantTest { 13 | 14 | @Test(expected = IOException.class) 15 | public void testStructWithPrimitiveConstantsFailsOnIntegerMember() throws IOException { 16 | ByteBuffer buffer = ByteBuffer.wrap(new byte[]{ 17 | 0x00, 18 | 0x00, 19 | 0x00, 0x00, 20 | 0x00, 0x00, 21 | 0x00, 0x00, 0x00, 0x00, 22 | 0x00, 0x00, 0x00, 0x00, 23 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 24 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 25 | 0x00, 0x00, 0x00, 0x00, 26 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); 27 | buffer.order(ByteOrder.LITTLE_ENDIAN); 28 | StructWithPrimitiveConstants.read(buffer); 29 | } 30 | 31 | @Test(expected = IOException.class) 32 | public void testStructWithPrimitiveConstantsFailsOnFloatMember() throws IOException { 33 | ByteBuffer buffer = ByteBuffer.wrap(new byte[]{ 34 | 0x01, 35 | 0x02, 36 | 0x03, 0x00, 37 | 0x04, 0x00, 38 | 0x05, 0x00, 0x00, 0x00, 39 | 0x06, 0x00, 0x00, 0x00, 40 | 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 41 | 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 | 0x00, 0x00, (byte)0x80, 0x3F, 43 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); 44 | buffer.order(ByteOrder.LITTLE_ENDIAN); 45 | StructWithPrimitiveConstants.read(buffer); 46 | } 47 | 48 | @Test(expected = IOException.class) 49 | public void testStructWithArrayConstantsFailsOnIntegerMember() throws IOException { 50 | ByteBuffer buffer = ByteBuffer.wrap(new byte[]{ 51 | 0x00, 52 | 0x00, 53 | 0x00, 0x00, 54 | 0x00, 0x00, 55 | 0x00, 0x00, 0x00, 0x00, 56 | 0x00, 0x00, 0x00, 0x00, 57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 | 0x00, 0x00, 0x00, 0x00, 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); 61 | buffer.order(ByteOrder.LITTLE_ENDIAN); 62 | StructWithArrayConstants.read(buffer); 63 | } 64 | 65 | @Test(expected = IOException.class) 66 | public void testStructWithArrayConstantsFailsOnFloatMember() throws IOException { 67 | ByteBuffer buffer = ByteBuffer.wrap(new byte[]{ 68 | 0x01, 69 | 0x02, 70 | 0x03, 0x00, 71 | 0x04, 0x00, 72 | 0x05, 0x00, 0x00, 0x00, 73 | 0x06, 0x00, 0x00, 0x00, 74 | 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 75 | 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 76 | 0x00, 0x00, (byte)0x80, 0x3F, 77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }); 78 | buffer.order(ByteOrder.LITTLE_ENDIAN); 79 | StructWithArrayConstants.read(buffer); 80 | } 81 | 82 | @Test(expected = IOException.class) 83 | public void testStructWithStringConstantFails() throws IOException { 84 | ByteBuffer buffer = ByteBuffer.wrap(new byte[]{0x74, 0x61, 0x73, 0x74}); 85 | buffer.order(ByteOrder.LITTLE_ENDIAN); 86 | StructWithStringConstant.read(buffer); 87 | } 88 | 89 | @Test 90 | public void testStructWithPrimitiveConstantsPasses() throws IOException { 91 | ByteBuffer buffer = ByteBuffer.wrap(new byte[]{ 92 | 0x01, 93 | 0x02, 94 | 0x03, 0x00, 95 | 0x04, 0x00, 96 | 0x05, 0x00, 0x00, 0x00, 97 | 0x06, 0x00, 0x00, 0x00, 98 | 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 99 | 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 100 | 0x00, 0x00, (byte)0x80, 0x3F, 101 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 }); 102 | buffer.order(ByteOrder.LITTLE_ENDIAN); 103 | StructWithPrimitiveConstants.read(buffer); 104 | } 105 | 106 | @Test 107 | public void testStructWithArrayConstantsPasses() throws IOException { 108 | ByteBuffer buffer = ByteBuffer.wrap(new byte[]{ 109 | 0x01, 110 | 0x02, 111 | 0x03, 0x00, 112 | 0x04, 0x00, 113 | 0x05, 0x00, 0x00, 0x00, 114 | 0x06, 0x00, 0x00, 0x00, 115 | 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 116 | 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 117 | 0x00, 0x00, (byte)0x80, 0x3F, 118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 }); 119 | buffer.order(ByteOrder.LITTLE_ENDIAN); 120 | StructWithArrayConstants.read(buffer); 121 | } 122 | 123 | @Test 124 | public void testStructWithStringConstantPasses() throws IOException { 125 | ByteBuffer buffer = ByteBuffer.wrap(new byte[]{0x74, 0x65, 0x73, 0x74}); 126 | buffer.order(ByteOrder.LITTLE_ENDIAN); 127 | StructWithStringConstant.read(buffer); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/test/java/org/structs4java/example/tests/DefaultValueTest.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | import org.junit.Test; 4 | import org.structs4java.example.tests.defaultvalues.*; 5 | 6 | import java.nio.ByteBuffer; 7 | import java.util.List; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class DefaultValueTest { 12 | @Test 13 | public void testStructWithIntegerDefaultValue() { 14 | StructWithIntegerDefaultValue struct = new StructWithIntegerDefaultValue(); 15 | assertEquals(1, struct.getInt8()); 16 | assertEquals(2, struct.getInt16()); 17 | assertEquals(3, struct.getInt32()); 18 | assertEquals(4, struct.getInt64()); 19 | } 20 | 21 | @Test 22 | public void testStructWithFloatDefaultValue() { 23 | StructWithFloatDefaultValue struct = new StructWithFloatDefaultValue(); 24 | assertEquals(1.0, struct.getF(), 0.001); 25 | assertEquals(2.0, struct.getD(), 0.001); 26 | } 27 | 28 | @Test 29 | public void testStructWithStringDefaultValue() { 30 | StructWithStringDefaultValue struct = new StructWithStringDefaultValue(); 31 | assertEquals("default", struct.getStr()); 32 | } 33 | 34 | @Test 35 | public void testStructWithEnumDefaultValue() { 36 | StructWithEnum struct = new StructWithEnum(); 37 | assertEquals(Int8Enum.B, struct.getInt8Enum()); 38 | } 39 | 40 | @Test 41 | public void testStructWithArrayDefaultValue() { 42 | StructWithArrayDefaultValue struct = new StructWithArrayDefaultValue(); 43 | assertBufferEquals(struct.getInt8(), 1, 0x20, 3); 44 | assertListEquals(struct.getInt16(), 4, 5, 6); 45 | assertListEquals(struct.getInt32(), 7, 8, 9); 46 | assertListEquals(struct.getInt64(), 0x10, 0x11, 0x12); 47 | } 48 | 49 | private void assertBufferEquals(ByteBuffer buffer, int... expected) { 50 | for(int value : expected) { 51 | assertEquals(value, buffer.get() & 0xFF); 52 | } 53 | } 54 | 55 | private void assertListEquals(List items, int... expected) { 56 | for(int i = 0; i < expected.length; ++i) { 57 | assertEquals(expected[i], items.get(i).longValue()); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /structs4java-maven-plugin-test/src/test/java/org/structs4java/example/tests/NullSafetyTest.java: -------------------------------------------------------------------------------- 1 | package org.structs4java.example.tests; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.assertNotNull; 6 | 7 | import java.io.IOException; 8 | import java.nio.ByteBuffer; 9 | 10 | import org.structs4java.example.tests.nullsafety.StructWithByteBuffer; 11 | import org.structs4java.example.tests.nullsafety.StructWithInt32Array; 12 | import org.structs4java.example.tests.nullsafety.StructWithStructArray; 13 | 14 | public class NullSafetyTest { 15 | 16 | @Test 17 | public void testWritingDefaultStructWithByteBuffer() throws IOException { 18 | ByteBuffer buffer = ByteBuffer.allocate(10); 19 | StructWithByteBuffer struct = new StructWithByteBuffer(); 20 | struct.write(buffer); 21 | } 22 | 23 | @Test 24 | public void testWritingDefaultStructWithInt32Array() throws IOException { 25 | ByteBuffer buffer = ByteBuffer.allocate(40); 26 | StructWithInt32Array struct = new StructWithInt32Array(); 27 | struct.write(buffer); 28 | } 29 | 30 | @Test 31 | public void testWritingDefaultStructWithStructArray() throws IOException { 32 | ByteBuffer buffer = ByteBuffer.allocate(400); 33 | StructWithStructArray struct = new StructWithStructArray(); 34 | struct.write(buffer); 35 | } 36 | 37 | @Test 38 | public void testDefaultStructWithInt32ArrayReturnsNotNull() { 39 | StructWithInt32Array struct = new StructWithInt32Array(); 40 | assertNotNull(struct.getArray()); 41 | } 42 | 43 | @Test 44 | public void testDefaultStructWithStructArrayReturnsNotNull() { 45 | StructWithStructArray struct = new StructWithStructArray(); 46 | assertNotNull(struct.getArray()); 47 | } 48 | 49 | @Test 50 | public void testDefaultStructWithByteBufferReturnsNotNull() { 51 | StructWithByteBuffer struct = new StructWithByteBuffer(); 52 | assertNotNull(struct.getBuffer()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /structs4java-maven-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.github.marc-christian-schulze.structs4java 5 | structs4java-maven-plugin 6 | 1.0.54-SNAPSHOT 7 | maven-plugin 8 | 9 | 10 | UTF-8 11 | 11 12 | 11 13 | 14 | 15 | ${project.groupId}:${project.artifactId} 16 | Structs4Java is a code generator based on C/C++ structures. 17 | https://github.com/marc-christian-schulze/structs4java 18 | 19 | 20 | Marc-Christian Schulze 21 | Marc.Christian.Schulze@gmail.com 22 | GitHub 23 | https://github.com/marc-christian-schulze 24 | 25 | 26 | 27 | 28 | The Apache License, Version 2.0 29 | http://www.apache.org/licenses/LICENSE-2.0.txt 30 | 31 | 32 | 33 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 34 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 35 | https://github.com/marc-christian-schulze/structs4java/tree/master 36 | 37 | 38 | 39 | 40 | org.apache.maven 41 | maven-plugin-api 42 | 3.3.9 43 | provided 44 | 45 | 46 | org.apache.maven.plugin-tools 47 | maven-plugin-annotations 48 | 3.4 49 | provided 50 | 51 | 52 | org.apache.maven 53 | maven-project 54 | 2.2.1 55 | provided 56 | 57 | 58 | org.apache.maven.shared 59 | file-management 60 | 3.1.0 61 | 62 | 63 | 64 | org.apache.maven 65 | maven-core 66 | 3.8.1 67 | provided 68 | 69 | 70 | 71 | com.github.marc-christian-schulze.structs4java 72 | structs4java-core 73 | ${project.version} 74 | 75 | 76 | 77 | 78 | 79 | 80 | org.apache.maven.plugins 81 | maven-source-plugin 82 | 3.1.0 83 | 84 | 85 | attach-sources 86 | 87 | jar 88 | 89 | 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-javadoc-plugin 95 | 2.10.4 96 | 97 | 98 | attach-javadocs 99 | 100 | jar 101 | 102 | 103 | 8 104 | 105 | 106 | 107 | 108 | 109 | org.apache.maven.plugins 110 | maven-plugin-plugin 111 | 3.15.1 112 | 113 | 114 | org.apache.maven.plugins 115 | maven-compiler-plugin 116 | 3.8.1 117 | 118 | 11 119 | 11 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | release 128 | 129 | 130 | 131 | org.apache.maven.plugins 132 | maven-gpg-plugin 133 | 3.0.1 134 | 135 | 136 | sign-artifacts 137 | verify 138 | 139 | sign 140 | 141 | 142 | 143 | --pinentry-mode 144 | loopback 145 | 146 | 147 | 148 | 149 | 150 | 151 | org.sonatype.central 152 | central-publishing-maven-plugin 153 | 0.6.0 154 | true 155 | 156 | central 157 | true 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /structs4java-maven-plugin/src/main/java/org/structs4java/AbstractCompileMojo.java: -------------------------------------------------------------------------------- 1 | package org.structs4java; 2 | 3 | import static com.google.common.collect.Iterables.filter; 4 | import static com.google.common.collect.Lists.newArrayList; 5 | 6 | import java.io.File; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | import java.util.List; 10 | import java.util.Set; 11 | import java.util.stream.Collectors; 12 | 13 | import edu.emory.mathcs.backport.java.util.Collections; 14 | import org.apache.maven.artifact.Artifact; 15 | import org.apache.maven.execution.MavenSession; 16 | import org.apache.maven.plugin.AbstractMojo; 17 | import org.apache.maven.plugin.BuildPluginManager; 18 | import org.apache.maven.plugin.MojoExecutionException; 19 | import org.apache.maven.plugin.logging.Log; 20 | import org.apache.maven.plugins.annotations.Component; 21 | import org.apache.maven.plugins.annotations.Parameter; 22 | import org.apache.maven.project.MavenProject; 23 | import org.apache.maven.shared.model.fileset.FileSet; 24 | import org.apache.maven.shared.model.fileset.util.FileSetManager; 25 | import org.apache.maven.toolchain.Toolchain; 26 | import org.apache.maven.toolchain.ToolchainManager; 27 | import org.apache.maven.toolchain.java.DefaultJavaToolChain; 28 | import org.codehaus.plexus.util.DirectoryScanner; 29 | import org.codehaus.plexus.util.xml.Xpp3Dom; 30 | 31 | import com.google.common.base.Predicate; 32 | 33 | public abstract class AbstractCompileMojo extends AbstractMojo { 34 | 35 | @Component 36 | private MavenProject project; 37 | 38 | @Component 39 | private MavenSession mavenSession; 40 | 41 | @Component 42 | private BuildPluginManager pluginManager; 43 | 44 | @Parameter 45 | private boolean skip; 46 | 47 | @Parameter 48 | private List includes; 49 | 50 | @Parameter 51 | private List excludes; 52 | 53 | @Parameter(defaultValue = "11") 54 | private String source; 55 | 56 | @Parameter(defaultValue = "11") 57 | private String target; 58 | 59 | private StructsBatchCompiler structsBatchCompiler; 60 | 61 | protected MavenLog4JConfigurator log4jConfigurator; 62 | 63 | protected MavenProject getProject() { 64 | return project; 65 | } 66 | 67 | protected abstract File getStructsDirectory(); 68 | 69 | public AbstractCompileMojo() { 70 | log4jConfigurator = new MavenLog4JConfigurator(); 71 | structsBatchCompiler = new StructsBatchCompiler(); 72 | } 73 | 74 | public void execute() throws MojoExecutionException { 75 | if(skip) { 76 | getLog().info("Skipping plugin execution due to configuration parameter 'skip' set to true."); 77 | return; 78 | } 79 | 80 | if (includes == null || includes.size() == 0) { 81 | includes = new ArrayList<>(); 82 | includes.add("**/*.structs"); 83 | } 84 | 85 | if (!getStructsDirectory().exists()) { 86 | getLog().info("Structs source directory does not exist: " + getStructsDirectory()); 87 | return; 88 | } 89 | 90 | FileSet structFileSet = new FileSet(); 91 | structFileSet.setIncludes(includes); 92 | structFileSet.setExcludes(excludes); 93 | structFileSet.setDirectory(getStructsDirectory().getAbsolutePath()); 94 | 95 | FileSetManager fsm = new FileSetManager(); 96 | // returns the array of matching filenames, relative to the basedir of the file-set. 97 | String[] structFiles = fsm.getIncludedFiles(structFileSet); 98 | 99 | log4jConfigurator.configureLog4j(getLog()); 100 | 101 | List compileSourceRoots = getCompileSourceRoots(); 102 | compileSourceRoots.remove(getOutputDirectory()); 103 | String classPath = String.join(File.pathSeparator, getClassPath()); 104 | project.addCompileSourceRoot(getOutputDirectory().toString()); 105 | compile(classPath, compileSourceRoots, Arrays.stream(structFiles).map(relativePath -> new File(getStructsDirectory(), relativePath)).collect(Collectors.toList()), getOutputDirectory().toString()); 106 | } 107 | 108 | protected abstract List getCompileSourceRoots(); 109 | 110 | protected abstract List getClassPath(); 111 | 112 | protected abstract File getOutputDirectory(); 113 | 114 | protected void addDependencies(Set classPath, List dependencies) { 115 | for (Artifact artifact : dependencies) { 116 | classPath.add(artifact.getFile().getAbsolutePath()); 117 | } 118 | } 119 | 120 | private String[] getValues(Xpp3Dom[] children) { 121 | String[] values = new String[children.length]; 122 | for (int i = 0; i < values.length; i++) { 123 | values[i] = children[i].getValue(); 124 | } 125 | return values; 126 | } 127 | 128 | private String scanBootclasspath(String javaHome, String[] includes, String[] excludes) { 129 | getLog().debug("Scanning bootClassPath:\n" + "\tjavaHome = " + javaHome + "\n" + "\tincludes = " 130 | + Arrays.toString(includes) + "\n" + "\texcludes = " + Arrays.toString(excludes)); 131 | DirectoryScanner scanner = new DirectoryScanner(); 132 | scanner.setBasedir(new File(javaHome)); 133 | scanner.setIncludes(includes); 134 | scanner.setExcludes(excludes); 135 | scanner.scan(); 136 | 137 | StringBuilder bootClassPath = new StringBuilder(); 138 | String[] includedFiles = scanner.getIncludedFiles(); 139 | for (int i = 0; i < includedFiles.length; i++) { 140 | if (i > 0) { 141 | bootClassPath.append(File.pathSeparator); 142 | } 143 | bootClassPath.append(new File(javaHome, includedFiles[i]).getAbsolutePath()); 144 | } 145 | return bootClassPath.toString(); 146 | } 147 | 148 | private String getBootClassPath() { 149 | Toolchain toolchain = toolchainManager.getToolchainFromBuildContext("jdk", session); 150 | if (toolchain instanceof DefaultJavaToolChain) { 151 | DefaultJavaToolChain javaToolChain = (DefaultJavaToolChain) toolchain; 152 | getLog().info("Using toolchain " + javaToolChain); 153 | 154 | String[] includes = { "jre/lib/*", "jre/lib/ext/*", "jre/lib/endorsed/*" }; 155 | String[] excludes = new String[0]; 156 | Xpp3Dom config = (Xpp3Dom) javaToolChain.getModel().getConfiguration(); 157 | if (config != null) { 158 | Xpp3Dom bootClassPath = config.getChild("bootClassPath"); 159 | if (bootClassPath != null) { 160 | Xpp3Dom includeParent = bootClassPath.getChild("includes"); 161 | if (includeParent != null) { 162 | includes = getValues(includeParent.getChildren("include")); 163 | } 164 | Xpp3Dom excludeParent = bootClassPath.getChild("excludes"); 165 | if (excludeParent != null) { 166 | excludes = getValues(excludeParent.getChildren("exclude")); 167 | } 168 | } 169 | } 170 | 171 | return scanBootclasspath(javaToolChain.getJavaHome(), includes, excludes); 172 | } 173 | return ""; 174 | } 175 | 176 | protected void compile(String classPath, List sourcePaths, List structFiles, String outputPath) 177 | throws MojoExecutionException { 178 | StructsBatchCompiler compiler = getBatchCompiler(); 179 | Log log = getLog(); 180 | Iterable filtered = filter(sourcePaths, FILE_EXISTS); 181 | log.debug("Set DeleteTempDirectory: " + false); 182 | compiler.setDeleteTempDirectory(false); 183 | log.debug("Set classpath: " + classPath); 184 | compiler.setClassPath(classPath); 185 | String bootClassPath = getBootClassPath(); 186 | log.debug("Set bootClasspath: " + bootClassPath); 187 | compiler.setBootClassPath(bootClassPath); 188 | log.debug("Set source path: " + String.join(File.pathSeparator, newArrayList(filtered))); 189 | compiler.setSourcePath(String.join(File.pathSeparator, newArrayList(filtered))); 190 | log.debug("Set output path: " + outputPath); 191 | compiler.setOutputPath(outputPath); 192 | log.debug("Set encoding: " + encoding); 193 | compiler.setFileEncoding(encoding); 194 | log.debug("Set structFiles: " + structFiles); 195 | compiler.setStructFiles(structFiles); 196 | log.debug("Set writeTraceFiles: " + writeTraceFiles); 197 | compiler.setWriteTraceFiles(writeTraceFiles); 198 | log.debug("Set source version: " + source); 199 | compiler.setSourceVersion(source); 200 | log.debug("Set target version: " + target); 201 | compiler.setTargetVersion(target); 202 | 203 | if (!compiler.compile()) { 204 | throw new MojoExecutionException("Compilation of structs sources failed."); 205 | } 206 | } 207 | 208 | protected StructsBatchCompiler getBatchCompiler() { 209 | return structsBatchCompiler; 210 | } 211 | 212 | protected static final Predicate FILE_EXISTS = new Predicate() { 213 | 214 | public boolean apply(String filePath) { 215 | return new File(filePath).exists(); 216 | } 217 | }; 218 | 219 | @Component 220 | private ToolchainManager toolchainManager; 221 | 222 | /** 223 | * The current build session instance. This is used for toolchain manager 224 | * API calls. 225 | * 226 | * @parameter expression="${session}" 227 | * @required 228 | * @readonly 229 | */ 230 | private MavenSession session; 231 | 232 | /** 233 | * Xtend-File encoding argument for the compiler. 234 | * 235 | * @parameter expression="${encoding}" 236 | * default-value="${project.build.sourceEncoding}" 237 | */ 238 | private String encoding; 239 | 240 | /** 241 | * Set this to false to suppress the creation of *._trace files. 242 | * 243 | * @parameter default-value="true" expression="${writeTraceFiles}" 244 | */ 245 | private boolean writeTraceFiles; 246 | 247 | } 248 | -------------------------------------------------------------------------------- /structs4java-maven-plugin/src/main/java/org/structs4java/CompileMojo.java: -------------------------------------------------------------------------------- 1 | package org.structs4java; 2 | 3 | import static com.google.common.collect.Iterables.filter; 4 | import static com.google.common.collect.Lists.newArrayList; 5 | 6 | import java.io.File; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | import org.apache.maven.artifact.DependencyResolutionRequiredException; 11 | import org.apache.maven.plugins.annotations.LifecyclePhase; 12 | import org.apache.maven.plugins.annotations.Mojo; 13 | import org.apache.maven.plugins.annotations.Parameter; 14 | import org.apache.maven.plugins.annotations.ResolutionScope; 15 | 16 | import com.google.common.collect.Lists; 17 | import com.google.common.collect.Sets; 18 | 19 | @Mojo(name = "compile", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, requiresDependencyCollection = ResolutionScope.COMPILE) 20 | public class CompileMojo extends AbstractCompileMojo { 21 | 22 | @Parameter(defaultValue = "${basedir}/src/main/structs") 23 | private File structsDirectory; 24 | 25 | @Parameter(defaultValue = "${project.build.directory}/structs-gen") 26 | private File outputDirectory; 27 | 28 | protected File getStructsDirectory() { 29 | return structsDirectory; 30 | } 31 | 32 | protected File getOutputDirectory() { 33 | return outputDirectory; 34 | } 35 | 36 | protected List getCompileSourceRoots() { 37 | return Lists.newArrayList(getProject().getCompileSourceRoots()); 38 | } 39 | 40 | protected List getClassPath() { 41 | Set classPath = Sets.newLinkedHashSet(); 42 | classPath.add(getProject().getBuild().getSourceDirectory()); 43 | try { 44 | classPath.addAll(getProject().getCompileClasspathElements()); 45 | } catch (DependencyResolutionRequiredException e) { 46 | throw new RuntimeException(e); 47 | } 48 | addDependencies(classPath, getProject().getCompileArtifacts()); 49 | classPath.remove(getProject().getBuild().getOutputDirectory()); 50 | return newArrayList(filter(classPath, FILE_EXISTS)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /structs4java-maven-plugin/src/main/java/org/structs4java/MavenLog4JConfigurator.java: -------------------------------------------------------------------------------- 1 | package org.structs4java; 2 | 3 | import org.apache.log4j.AppenderSkeleton; 4 | import org.apache.log4j.Level; 5 | import org.apache.log4j.Logger; 6 | import org.apache.log4j.spi.LoggingEvent; 7 | import org.apache.maven.plugin.logging.Log; 8 | 9 | /** 10 | * @author Michael Clay 11 | * @author Moritz Eysholdt 12 | */ 13 | public class MavenLog4JConfigurator { 14 | 15 | protected final static Level LOG4J_DEFAULT_LOG_LEVEL = Level.INFO; 16 | 17 | public void configureLog4j(Log log) { 18 | if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) { 19 | try { 20 | Logger.getRootLogger().setLevel(LOG4J_DEFAULT_LOG_LEVEL); 21 | } catch (NoSuchMethodError e) { 22 | // see http://bugzilla.slf4j.org/show_bug.cgi?id=279 23 | } 24 | Logger.getRootLogger().addAppender(createMojoLogAppender(log)); 25 | } else { 26 | configureLog4j(log, "org.structs4java"); 27 | } 28 | } 29 | 30 | protected void configureLog4j(Log log, String name) { 31 | Logger logger = Logger.getLogger(name); 32 | logger.setAdditivity(false); 33 | try { 34 | logger.setLevel(LOG4J_DEFAULT_LOG_LEVEL); 35 | } catch (NoSuchMethodError e) { 36 | // see http://bugzilla.slf4j.org/show_bug.cgi?id=279 37 | } 38 | logger.removeAllAppenders(); 39 | logger.addAppender(createMojoLogAppender(log)); 40 | } 41 | 42 | protected AppenderSkeleton createMojoLogAppender(final Log log) { 43 | return new AppenderSkeleton() { 44 | 45 | @Override 46 | protected void append(LoggingEvent event) { 47 | if (event.getMessage() == null) { 48 | return; 49 | } 50 | if (Level.DEBUG == event.getLevel()) { 51 | log.debug((CharSequence) event.getMessage(), getThrowable(event)); 52 | } else if (Level.INFO == event.getLevel()) { 53 | log.info((CharSequence) event.getMessage(), getThrowable(event)); 54 | } else if (Level.WARN == event.getLevel()) { 55 | log.warn((CharSequence) event.getMessage(), getThrowable(event)); 56 | } else if (Level.ERROR == event.getLevel()) { 57 | log.error((CharSequence) event.getMessage(), getThrowable(event)); 58 | } 59 | } 60 | 61 | public void close() { 62 | } 63 | 64 | private Throwable getThrowable(LoggingEvent event) { 65 | return event.getThrowableInformation() != null ? event.getThrowableInformation().getThrowable() : null; 66 | } 67 | 68 | public boolean requiresLayout() { 69 | return false; 70 | } 71 | }; 72 | } 73 | } -------------------------------------------------------------------------------- /structs4java-maven-plugin/src/main/java/org/structs4java/TestCompileMojo.java: -------------------------------------------------------------------------------- 1 | package org.structs4java; 2 | 3 | import static com.google.common.collect.Iterables.filter; 4 | import static com.google.common.collect.Lists.newArrayList; 5 | 6 | import java.io.File; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | import org.apache.maven.artifact.DependencyResolutionRequiredException; 11 | import org.apache.maven.plugins.annotations.LifecyclePhase; 12 | import org.apache.maven.plugins.annotations.Mojo; 13 | import org.apache.maven.plugins.annotations.Parameter; 14 | import org.apache.maven.plugins.annotations.ResolutionScope; 15 | 16 | import com.google.common.collect.Lists; 17 | import com.google.common.collect.Sets; 18 | 19 | @Mojo(name = "testCompile", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, requiresDependencyCollection = ResolutionScope.COMPILE) 20 | public class TestCompileMojo extends AbstractCompileMojo { 21 | 22 | @Parameter(defaultValue = "${basedir}/src/test/structs") 23 | private File structsDirectory; 24 | 25 | @Parameter(defaultValue = "${project.build.testOutputDirectory}/structs-gen") 26 | private File outputDirectory; 27 | 28 | protected File getStructsDirectory() { 29 | return structsDirectory; 30 | } 31 | 32 | protected File getOutputDirectory() { 33 | return outputDirectory; 34 | } 35 | 36 | protected List getCompileSourceRoots() { 37 | return Lists.newArrayList(getProject().getTestCompileSourceRoots()); 38 | } 39 | 40 | protected List getClassPath() { 41 | Set classPath = Sets.newLinkedHashSet(); 42 | classPath.add(getProject().getBuild().getTestSourceDirectory()); 43 | try { 44 | classPath.addAll(getProject().getTestClasspathElements()); 45 | } catch (DependencyResolutionRequiredException e) { 46 | throw new RuntimeException(e); 47 | } 48 | addDependencies(classPath, getProject().getTestArtifacts()); 49 | classPath.remove(getProject().getBuild().getTestOutputDirectory()); 50 | return newArrayList(filter(classPath, FILE_EXISTS)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /structs4java-with-dependencies/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.github.marc-christian-schulze.structs4java 5 | structs4java-with-dependencies 6 | 1.0.54-SNAPSHOT 7 | jar 8 | 9 | 10 | UTF-8 11 | 12 | 13 | ${project.groupId}:${project.artifactId} 14 | Structs4Java is a code generator based on C/C++ structures. 15 | https://github.com/marc-christian-schulze/structs4java 16 | 17 | 18 | Marc-Christian Schulze 19 | Marc.Christian.Schulze@gmail.com 20 | GitHub 21 | https://github.com/marc-christian-schulze 22 | 23 | 24 | 25 | 26 | The Apache License, Version 2.0 27 | http://www.apache.org/licenses/LICENSE-2.0.txt 28 | 29 | 30 | 31 | scm:git:git://github.com/marc-christian-schulze/structs4java.git 32 | scm:git:ssh://github.com:marc-christian-schulze/structs4java.git 33 | https://github.com/marc-christian-schulze/structs4java/tree/master 34 | 35 | 36 | 37 | 38 | com.github.marc-christian-schulze.structs4java 39 | org.structs4java 40 | ${project.version} 41 | 42 | 43 | org.eclipse.xtext 44 | org.eclipse.xtext 45 | 2.28.0 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-source-plugin 54 | 3.0.1 55 | 56 | 57 | attach-sources 58 | 59 | jar 60 | 61 | 62 | 63 | 64 | 65 | org.apache.maven.plugins 66 | maven-javadoc-plugin 67 | 2.10.4 68 | 69 | 70 | attach-javadocs 71 | 72 | jar 73 | 74 | 75 | 8 76 | 77 | 78 | 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-plugin-plugin 83 | 84 | 3.4 85 | 86 | 87 | org.apache.maven.plugins 88 | maven-compiler-plugin 89 | 3.6.1 90 | 91 | 1.8 92 | 1.8 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-dependency-plugin 98 | 99 | 100 | copy-dependencies 101 | prepare-package 102 | 103 | copy-dependencies 104 | 105 | 106 | ${project.build.directory}/classes/lib 107 | false 108 | false 109 | true 110 | runtime 111 | 112 | 113 | 114 | 115 | 116 | org.apache.maven.plugins 117 | maven-jar-plugin 118 | 2.4 119 | 120 | 121 | 122 | true 123 | 124 | 125 | lib/ 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | --------------------------------------------------------------------------------