From 4de039939bbb417974c6a4710addebc68552e43b Mon Sep 17 00:00:00 2001 From: Jeff Maxwell Date: Fri, 29 Apr 2022 14:55:28 -0500 Subject: [PATCH] MCOMPILER-495 create missing dirs in createMissingPackageInfoClasses --- src/it/MCOMPILER-495/invoker.properties | 19 ++++++++ src/it/MCOMPILER-495/pom.xml | 44 +++++++++++++++++++ .../src/main/java/dummy/package-info.java | 23 ++++++++++ src/it/MCOMPILER-495/verify.groovy | 24 ++++++++++ .../plugin/compiler/AbstractCompilerMojo.java | 7 +++ 5 files changed, 117 insertions(+) create mode 100644 src/it/MCOMPILER-495/invoker.properties create mode 100644 src/it/MCOMPILER-495/pom.xml create mode 100644 src/it/MCOMPILER-495/src/main/java/dummy/package-info.java create mode 100644 src/it/MCOMPILER-495/verify.groovy diff --git a/src/it/MCOMPILER-495/invoker.properties b/src/it/MCOMPILER-495/invoker.properties new file mode 100644 index 00000000..8595721d --- /dev/null +++ b/src/it/MCOMPILER-495/invoker.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +invoker.goals = clean compile +invoker.buildResult = success diff --git a/src/it/MCOMPILER-495/pom.xml b/src/it/MCOMPILER-495/pom.xml new file mode 100644 index 00000000..bc6f4f24 --- /dev/null +++ b/src/it/MCOMPILER-495/pom.xml @@ -0,0 +1,44 @@ + + + + + 4.0.0 + + blah + blah + 1.0 + jar + + + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + @pom.version@ + + + + diff --git a/src/it/MCOMPILER-495/src/main/java/dummy/package-info.java b/src/it/MCOMPILER-495/src/main/java/dummy/package-info.java new file mode 100644 index 00000000..ed72542b --- /dev/null +++ b/src/it/MCOMPILER-495/src/main/java/dummy/package-info.java @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * This is the package javadoc + */ +package dummy; \ No newline at end of file diff --git a/src/it/MCOMPILER-495/verify.groovy b/src/it/MCOMPILER-495/verify.groovy new file mode 100644 index 00000000..2384fecd --- /dev/null +++ b/src/it/MCOMPILER-495/verify.groovy @@ -0,0 +1,24 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +def packageInfoClassFile = new File( basedir, 'target/classes/dummy/package-info.class' ) +def packageInfoBytes = packageInfoClassFile.bytes +def packageInfoHex = packageInfoBytes.encodeHex().toString() +// "dummy/package-info" hex encoded +assert packageInfoHex.contains( '64756d6d792f7061636b6167652d696e666f' ) diff --git a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java index a97b36d2..cf6b86ce 100644 --- a/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java +++ b/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java @@ -1374,6 +1374,13 @@ private void createMissingPackageInfoClasses( CompilerConfiguration compilerConf { if ( !file.exists() ) { + File parentFile = file.getParentFile(); + + if ( !parentFile.exists() ) + { + Files.createDirectories( parentFile.toPath() ); + } + byte[] bytes = generatePackage( compilerConfiguration, rel ); Files.write( file.toPath(), bytes ); }