/*
 * Copyright 2012-2013 the original author or authors.
 *
 * 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.
 */

package org.springframework.boot.cli;

import java.io.File;

import org.springframework.boot.cli.command.CleanCommand;

/**
 * @author Dave Syer
 */
public class GrapesCleaner {

	// FIXME get the version
	private static final String VERSION = "0.5.0.BUILD-SNAPSHOT";

	public static void cleanIfNecessary() throws Exception {
		File installedJar = new File(getMavenRepository(), String.format(
				"org/springframework/boot/spring-boot-strap/%s/spring-boot-strap-%s.jar",
				VERSION, VERSION));
		File grapesJar = new File(
				getGrapesCache(),
				String.format(
						"org.springframework.boot/spring-boot-strap/jars/spring-boot-strap-%s.jar",
						VERSION));
		if (!VERSION.contains("SNAPSHOT") || installedJar.exists() && grapesJar.exists()
				&& installedJar.lastModified() <= grapesJar.lastModified()) {
			return;
		}
		new CleanCommand().run();
	}

	private static File getMavenRepository() {
		return new File(System.getProperty("user.home"), ".m2/repository");
	}

	private static File getGrapesCache() {
		return new File(System.getProperty("user.home"), ".groovy/grapes");
	}

}

@@ -1051,22 +1051,16 @@
 ing-boot
--strap
 /%25s/spri
@@ -1063,38 +1063,32 @@
 spring-boot-
-strap-
 %25s.jar%22,
 %0A%09%09%09%09VERSION
@@ -1079,21 +1079,17 @@
 ar%22,
-%0A%09%09%09%09
+ 
 VERSION,
  VER
@@ -1084,17 +1084,21 @@
 VERSION,
- 
+%0A%09%09%09%09
 VERSION)
@@ -1128,21 +1128,16 @@
 ew File(
-%0A%09%09%09%09
 getGrape
@@ -1145,21 +1145,17 @@
 Cache(),
-%0A%09%09%09%09
+ 
 String.f
@@ -1161,18 +1161,16 @@
 format(%0A
-%09%09
 %09%09%09%09%22org
@@ -1202,22 +1202,16 @@
 ing-boot
--strap
 /jars/sp
@@ -1224,22 +1224,16 @@
 oot-
-strap-
 %25s.jar%22,
 %0A%09%09%09
@@ -1232,15 +1232,9 @@
 ar%22,
-%0A%09%09%09%09%09%09
+ 
 VERS

Fix GrapesCleaner to work with renamed artifacts