Author: tfischer Date: Sun Sep 20 20:48:09 2015 New Revision: 1704192 URL: http://svn.apache.org/viewvc?rev=1704192&view=rev Log: TORQUE-338: fix storing of checksums with more than one generation unit using the same cache file Thanks to Helge Weissig for the patch
Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/RunOnlyOnSourceChangeTest.java db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/package.html db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/conf/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/conf/control.xml db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/outlets/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/outlets/outlets.xml db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/changedSource.xml db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/unchangedSource.xml db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/changedSource.xml db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/unchangedSource.xml db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/templates/ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/templates/template.vm Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Checksums.java Modified: db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Checksums.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Checksums.java?rev=1704192&r1=1704191&r2=1704192&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Checksums.java (original) +++ db/torque/torque4/trunk/torque-generator/src/main/java/org/apache/torque/generator/control/Checksums.java Sun Sep 20 20:48:09 2015 @@ -128,6 +128,29 @@ public class Checksums Set<String> keys = new HashSet<String>(); keys.addAll(checksums.keySet()); keys.addAll(modificationDates.keySet()); + + Checksums existing = new Checksums(); + existing.readFromFile(toWriteTo); + for (String key : existing.getChecksums().keySet()) + { + if (keys.add(key)) + { + checksums.put(key, existing.getChecksum(key)); + if (existing.getModificationDate(key) != null) + { + modificationDates.put(key, existing.getModificationDate(key)); + } + } + } + + for (String key : existing.getModificationDates().keySet()) + { + if (keys.add(key)) + { + modificationDates.put(key, existing.getModificationDate(key)); + } + } + StringBuilder content = new StringBuilder(); for (String key : keys) { Added: db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/RunOnlyOnSourceChangeTest.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/RunOnlyOnSourceChangeTest.java?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/RunOnlyOnSourceChangeTest.java (added) +++ db/torque/torque4/trunk/torque-generator/src/test/java/org/apache/torque/generator/control/RunOnlyOnSourceChangeTest.java Sun Sep 20 20:48:09 2015 @@ -0,0 +1,118 @@ +package org.apache.torque.generator.control; + +/* + * 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. + */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.apache.torque.generator.BaseTest; +import org.apache.torque.generator.configuration.UnitDescriptor; +import org.apache.torque.generator.configuration.paths.CustomProjectPaths; +import org.apache.torque.generator.configuration.paths.DefaultTorqueGeneratorPaths; +import org.apache.torque.generator.configuration.paths.Maven2DirectoryProjectPaths; +import org.junit.Test; + +/** + * Tests nested mergepoints in a depth of 10 calls, and checks that the + * outcome is correct. + */ +public class RunOnlyOnSourceChangeTest extends BaseTest +{ + @Test + public void testRunOnlyOnSourceChange() throws Exception + { + File targetDir = new File("target/test/runOnlyOnSourceChange"); + FileUtils.deleteDirectory(targetDir); + File srcDir1 = new File(targetDir, "src/1"); + File srcDir2 = new File(targetDir, "src/2"); + FileUtils.copyDirectory(new File("src/test/runOnlyOnSourceChange/src/main/torque-gen/src"), srcDir1); + FileUtils.copyDirectory(new File("src/test/runOnlyOnSourceChange/src/main/torque-gen/src"), srcDir2); + Controller controller = new Controller(); + + // run first generation with two unit descriptors to reproduce TORQUE-338 + List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>(); + CustomProjectPaths projectPaths = new CustomProjectPaths( + new Maven2DirectoryProjectPaths( + new File("src/test/runOnlyOnSourceChange"))); + File targetDir1 = new File(targetDir, "1"); + projectPaths.setOutputDirectory(null, targetDir1); + projectPaths.setSourceDir(srcDir1); + projectPaths.setCacheDir(new File("target/test/runOnlyOnSourceChange/cache")); + unitDescriptors.add(new UnitDescriptor( + UnitDescriptor.Packaging.DIRECTORY, + projectPaths, + new DefaultTorqueGeneratorPaths())); + unitDescriptors.get(0).setRunOnlyOnSourceChange(true); + + projectPaths = new CustomProjectPaths( + new Maven2DirectoryProjectPaths( + new File("src/test/runOnlyOnSourceChange"))); + File targetDir2 = new File(targetDir, "2"); + projectPaths.setOutputDirectory(null, targetDir2); + projectPaths.setSourceDir(srcDir2); + projectPaths.setCacheDir(new File("target/test/runOnlyOnSourceChange/cache")); + unitDescriptors.add(new UnitDescriptor( + UnitDescriptor.Packaging.DIRECTORY, + projectPaths, + new DefaultTorqueGeneratorPaths())); + unitDescriptors.get(1).setRunOnlyOnSourceChange(true); + + controller.run(unitDescriptors); + + // check outcome of first generation + assertTrue(targetDir.exists()); + + long unchangedTargetFile1LastModified = assertFile(targetDir1, "unchangedOutput.txt", "unchangedValue"); + long changedTargetFile11LastModified = assertFile(targetDir1, "changedOutput1.txt", "valueToBeChanged"); + long changedTargetFile12LastModified = assertFile(targetDir1, "changedOutput2.txt", "valueToBeChanged"); + long unchangedTargetFile2LastModified = assertFile(targetDir2, "unchangedOutput.txt", "unchangedValue"); + long changedTargetFile21LastModified = assertFile(targetDir2, "changedOutput1.txt", "valueToBeChanged"); + long changedTargetFile22LastModified = assertFile(targetDir2, "changedOutput2.txt", "valueToBeChanged"); + + // second run + FileUtils.deleteDirectory(srcDir1); + FileUtils.deleteDirectory(srcDir2); + FileUtils.copyDirectory(new File("src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource"), srcDir1); + FileUtils.copyDirectory(new File("src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource"), srcDir2); + controller.run(unitDescriptors); + + // check outcome of second generation + assertTrue(unchangedTargetFile1LastModified == assertFile(targetDir1, "unchangedOutput.txt", "unchangedValue")); + assertTrue(changedTargetFile11LastModified < assertFile(targetDir1, "changedOutput1.txt", "changedValue")); + assertTrue(changedTargetFile12LastModified < assertFile(targetDir1, "changedOutput2.txt", "changedValue")); + assertTrue(unchangedTargetFile2LastModified == assertFile(targetDir2, "unchangedOutput.txt", "unchangedValue")); + assertTrue(changedTargetFile21LastModified < assertFile(targetDir2, "changedOutput1.txt", "changedValue")); + assertTrue(changedTargetFile22LastModified < assertFile(targetDir2, "changedOutput2.txt", "changedValue")); + } + + private long assertFile(final File targetDir, final String filename, final String expectedContent) throws IOException + { + File targetFile = new File(targetDir, filename); + assertTrue(targetFile.exists()); + assertEquals(expectedContent, FileUtils.readFileToString(targetFile, "ISO-8859-1")); + return targetFile.lastModified(); + } +} Added: db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/package.html URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/package.html?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/package.html (added) +++ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/package.html Sun Sep 20 20:48:09 2015 @@ -0,0 +1,24 @@ +<!-- + Copyright 2001-2006 The Apache Software Foundation. + + Licensed under the Apache License, Version 2.0 (the "License") + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + 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. +--> + +<h2>Test configuration for the RunOnlyOnSourceChangeTest</h2> + +<p> + This directory and its subdirectories contain a test configuration + which is used by the RunOnlyOnSourceChangeTest to check whether + output encoding settings work correctly. +</p> + \ No newline at end of file Added: db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/conf/control.xml URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/conf/control.xml?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/conf/control.xml (added) +++ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/conf/control.xml Sun Sep 20 20:48:09 2015 @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<control + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd" + xmlns="http://db.apache.org/torque/4.0/generator/configuration"> + + <output name="changedOutput1" file="changedOutput1.txt"> + <source xsi:type="fileSource"> + <include>changedSource.xml</include> + </source> + <outlet name="org.apache.torque.generator.test.runOnlyOnSchemaChange"/> + </output> + <output name="unchangedOutput" file="unchangedOutput.txt"> + <source xsi:type="fileSource"> + <include>unchangedSource.xml</include> + </source> + <outlet name="org.apache.torque.generator.test.runOnlyOnSchemaChange"/> + </output> + <output name="changedOutput2" file="changedOutput2.txt"> + <source xsi:type="fileSource"> + <include>changedSource.xml</include> + </source> + <outlet name="org.apache.torque.generator.test.runOnlyOnSchemaChange"/> + </output> +</control> + \ No newline at end of file Added: db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/outlets/outlets.xml URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/outlets/outlets.xml?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/outlets/outlets.xml (added) +++ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/outlets/outlets.xml Sun Sep 20 20:48:09 2015 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> + +<torqueGenConf:outlets xmlns="http://db.apache.org/torque/4.0/generator/configuration" + xmlns:torqueGenConf="http://db.apache.org/torque/4.0/generator/configuration" + xsi:schemaLocation="http://db.apache.org/torque/4.0/generator/configuration http://db.apache.org/torque/4.0/generator/configuration.xsd" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <outlet name="org.apache.torque.generator.test.runOnlyOnSchemaChange" + xsi:type="velocityOutlet" + path="template.vm"/> +</torqueGenConf:outlets> \ No newline at end of file Added: db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/changedSource.xml URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/changedSource.xml?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/changedSource.xml (added) +++ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/changedSource.xml Sun Sep 20 20:48:09 2015 @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<source> + <entry value="changedValue" /> +</source> Added: db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/unchangedSource.xml URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/unchangedSource.xml?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/unchangedSource.xml (added) +++ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/secondSource/unchangedSource.xml Sun Sep 20 20:48:09 2015 @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<source> + <entry value="unchangedValue" /> +</source> Added: db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/changedSource.xml URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/changedSource.xml?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/changedSource.xml (added) +++ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/changedSource.xml Sun Sep 20 20:48:09 2015 @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<source> + <entry value="valueToBeChanged" /> +</source> Added: db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/unchangedSource.xml URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/unchangedSource.xml?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/unchangedSource.xml (added) +++ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/src/unchangedSource.xml Sun Sep 20 20:48:09 2015 @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<source> + <entry value="unchangedValue" /> +</source> Added: db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/templates/template.vm URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/templates/template.vm?rev=1704192&view=auto ============================================================================== --- db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/templates/template.vm (added) +++ db/torque/torque4/trunk/torque-generator/src/test/runOnlyOnSourceChange/src/main/torque-gen/templates/template.vm Sun Sep 20 20:48:09 2015 @@ -0,0 +1,20 @@ +## 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. +## +#foreach($childElement in ${torqueGen.getSourceElement().getChildren()}) +${childElement.getAttribute("value")}## +#end \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org For additional commands, e-mail: torque-dev-h...@db.apache.org