2015-10-05 16:10:44 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
2015-08-06 18:49:57 +02:00
|
|
|
|
2015-03-09 17:35:19 +01:00
|
|
|
package appeng.services.version;
|
|
|
|
|
|
|
|
|
2015-10-05 16:10:44 +02:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.services.version.exceptions.VersionCheckerException;
|
|
|
|
|
|
|
|
|
2015-03-09 17:35:19 +01:00
|
|
|
/**
|
|
|
|
* Wrapper for {@link VersionParser} to check if the check is happening in developer environment or in a pull request.
|
|
|
|
*
|
|
|
|
* In that case ignore the check.
|
|
|
|
*/
|
|
|
|
public final class ModVersionFetcher implements VersionFetcher
|
|
|
|
{
|
2015-10-05 16:10:44 +02:00
|
|
|
private static final Version EXCEPTIONAL_VERSION = new MissingVersion();
|
|
|
|
|
|
|
|
@Nonnull
|
2015-03-09 17:35:19 +01:00
|
|
|
private final String rawModVersion;
|
2015-10-05 16:10:44 +02:00
|
|
|
@Nonnull
|
2015-03-09 17:35:19 +01:00
|
|
|
private final VersionParser parser;
|
|
|
|
|
2015-10-05 16:10:44 +02:00
|
|
|
public ModVersionFetcher( @Nonnull final String rawModVersion, @Nonnull final VersionParser parser )
|
2015-03-09 17:35:19 +01:00
|
|
|
{
|
|
|
|
this.rawModVersion = rawModVersion;
|
|
|
|
this.parser = parser;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses only, if not checked in developer environment or in a pull request
|
|
|
|
*
|
2015-10-05 16:10:44 +02:00
|
|
|
* @return {@link DoNotCheckVersion} if in developer environment or pull request, {@link MissingVersion} in case of
|
|
|
|
* a parser exception or else the parsed {@link Version}.
|
2015-03-09 17:35:19 +01:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public Version get()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.rawModVersion.equals( "@version@" ) || this.rawModVersion.contains( "pr" ) )
|
2015-03-09 17:35:19 +01:00
|
|
|
{
|
|
|
|
return new DoNotCheckVersion();
|
|
|
|
}
|
2015-10-05 16:10:44 +02:00
|
|
|
|
|
|
|
try
|
2015-03-09 17:35:19 +01:00
|
|
|
{
|
|
|
|
final Version version = this.parser.parse( this.rawModVersion );
|
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|
2015-10-05 16:10:44 +02:00
|
|
|
catch( final VersionCheckerException e )
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
|
|
|
|
return EXCEPTIONAL_VERSION;
|
|
|
|
}
|
2015-03-09 17:35:19 +01:00
|
|
|
}
|
|
|
|
}
|