Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Maven中创建两个文件的一个校验和,以便在目录名中使用它_Maven - Fatal编程技术网

如何在Maven中创建两个文件的一个校验和,以便在目录名中使用它

如何在Maven中创建两个文件的一个校验和,以便在目录名中使用它,maven,Maven,我正在用Maven创建一个目录(本地EclipseB3聚合器/P2镜像) 两个配置文件(A.target、B.target)用于创建此目录 如果这些配置文件发生更改,则应创建新的镜像目录 我想将配置文件的校验和添加到镜像目录的名称中(例如,mirror65EB5293D29682A3414E8889A84104EE) 我可以使用“maven assembly plugin”创建一个包含配置文件的jar,但是如何创建这个jar的校验和呢 “校验和maven插件”只将校验和写入csv文件,我必须以某

我正在用Maven创建一个目录(本地EclipseB3聚合器/P2镜像)

两个配置文件(A.target、B.target)用于创建此目录

如果这些配置文件发生更改,则应创建新的镜像目录

我想将配置文件的校验和添加到镜像目录的名称中(例如,mirror65EB5293D29682A3414E8889A84104EE)

我可以使用“maven assembly plugin”创建一个包含配置文件的jar,但是如何创建这个jar的校验和呢

“校验和maven插件”只将校验和写入csv文件,我必须以某种方式进行解析

是否有方法将校验和创建到属性中,以便我可以使用它将其添加到目录的名称中

更新:

我现在的解决方案是使用shell脚本创建校验和并将其写入属性文件

#/bin/bash
os=$(uname)
如果[[“$os”==“Linux”];
然后
校验和=$(类别{A,B}.target | md5sum | awk'{print$1}')
elif[“$os”==“Darwin”];然后
校验和=$(类别{A,B}.target | md5-q)
其他的
echo“未知OS${OS}”
出口1
fi
printf“checksum=%s”“${checksum}”>。/checksum.properties
然后我可以使用properties maven插件从这个属性文件中读取校验和


org.codehaus.mojo
属性maven插件
1.0-α-2
初始化
读取项目属性
/checksum.properties

调整配置文件的位置后,请使用以下命令:

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.gmavenplus</groupId>
      <artifactId>gmavenplus-plugin</artifactId>
      <version>1.5</version>
      <executions>
        <execution>
          <id>set-property</id>
          <phase>process-resources</phase>
          <goals>
            <goal>execute</goal>
          </goals>
          <configuration>
            <scripts>
              <script>
                import java.nio.file.Path
                import java.nio.file.FileSystems
                import java.nio.file.Files
                import java.io.BufferedInputStream
                import java.security.MessageDigest
                import javax.xml.bind.annotation.adapters.HexBinaryAdapter

                Path pathA = FileSystems.getDefault().getPath('src/main/resources/A.target')
                Path pathB = FileSystems.getDefault().getPath('src/main/resources/B.target')

                byte[] configsBytes = new byte[Files.size(pathA) + Files.size(pathB)]

                InputStream inA = new BufferedInputStream(Files.newInputStream(pathA))
                inA.read(configsBytes)
                inA.close()

                InputStream inB = new BufferedInputStream(Files.newInputStream(pathB))
                inB.read(configsBytes, (int)Files.size(pathA), (int)Files.size(pathB))
                inB.close()

                MessageDigest md5 = MessageDigest.getInstance('MD5')
                // from http://stackoverflow.com/a/12514417/1744774
                String digest = new HexBinaryAdapter().marshal(md5.digest(configsBytes))
                log.info(String.format('Setting property configs.checksum to %s', digest))
                project.properties.setProperty('configs.checksum', digest)

                // InvocationTargetException: No such property: configs
                //log.info(String.format('Property configs.checksum=%s', "${configs.checksum}"))
              </script>
            </scripts>
          </configuration>
        </execution>

        <execution>
          <id>use-property</id>
          <phase>process-resources</phase>
          <goals>
            <goal>execute</goal>
          </goals>
          <configuration>
            <scripts>
              <script>
                // ...
                log.info(String.format('Property configs.checksum=%s', "${configs.checksum}"))
                // ...
              </script>
            </scripts>
          </configuration>
        </execution>
      </executions>

      <dependencies>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-all</artifactId>
          <version>2.4.3</version>
          <scope>runtime</scope>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building main 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- gmavenplus-plugin:1.5:execute (set-property) @ main ---
[INFO] Using Groovy 2.4.3 to perform execute.
[INFO] Setting property configs.checksum to 567A4B1644EA9ACB6FC047C1B4C5624B
[INFO]
[INFO] --- gmavenplus-plugin:1.5:execute (use-property) @ main ---
[INFO] Using Groovy 2.4.3 to perform execute.
[INFO] Property configs.checksum=567A4B1644EA9ACB6FC047C1B4C5624B
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.682 s
[INFO] Finished at: 2015-06-06T06:34:30+01:00
[INFO] Final Memory: 14M/111M
[INFO] ------------------------------------------------------------------------