Better method naming.

Better method naming.

/*
 * Copyright 2011 Google Inc.
 *
 * 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.
 *
 * This code has been modified by Stefano Dacchille.
 */

package com.github.ignition.location;

import org.aspectj.lang.annotation.SuppressAjWarnings;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import com.github.ignition.location.annotations.IgnitedLocation;
import com.github.ignition.location.annotations.IgnitedLocationActivity;
import com.github.ignition.location.receivers.IgnitedLocationChangedReceiver;
import com.github.ignition.location.receivers.IgnitedPassiveLocationChangedReceiver;
import com.github.ignition.location.tasks.IgnitedLastKnownLocationAsyncTask;
import com.github.ignition.location.templates.ILastLocationFinder;
import com.github.ignition.location.templates.IgnitedAbstractLastLocationFinder;
import com.github.ignition.location.templates.IgnitedAbstractLocationUpdateRequester;
import com.github.ignition.location.templates.OnIgnitedLocationChangedListener;
import com.github.ignition.location.utils.IgnitedLocationSupport;
import com.github.ignition.location.utils.PlatformSpecificImplementationFactory;
import com.github.ignition.support.IgnitedDiagnostics;

@SuppressAjWarnings
public aspect IgnitedLocationManager {
    public static final String LOG_TAG = IgnitedLocationManager.class.getSimpleName();

    declare parents : (@IgnitedLocationActivity *) implements OnIgnitedLocationChangedListener;

    private Criteria defaultCriteria, lowPowerCriteria;
    protected IgnitedAbstractLocationUpdateRequester locationUpdateRequester;
    protected PendingIntent locationListenerPendingIntent, locationListenerPassivePendingIntent;
    protected LocationManager locationManager;
    protected IgnitedLocationListener bestInactiveLocationProviderListener;

    private Context context;
    private volatile Location currentLocation;

    private IgnitedLastKnownLocationAsyncTask ignitedLastKnownLocationTask;
    private SharedPreferences prefs;
    private Handler handler;

    private long locationUpdatesInterval, passiveLocationUpdatesInterval;
    private int locationUpdatesDistanceDiff;
    private int passiveLocationUpdatesDistanceDiff;
    private boolean requestLocationUpdates = false;
    private boolean locationUpdatesDisabled = true;
    private boolean waitForFixDialogShown = false;
    private boolean noProvidersEnabledDialogShown = false;
    private boolean locationProviderDisabledReceiverRegistered = false;
    private boolean refreshLocationUpdatesReceiverRegistered = false;

    // Switch to another provider if gps doesn't return a location quickly enough.
    private Runnable removeGpsUpdates = new Runnable() {
        @Override
        public void run() {
            Log.d(LOG_TAG,
                    "It looks like GPS isn't available at this time (i.e.: maybe you're indoors). Removing GPS location updates and requesting network updates.");

            disableLocationUpdates(false);
            requestLocationUpdates(context, lowPowerCriteria());
        }
    };

    /**
     * If the Location Provider we're using to receive location updates is disabled while the app is
     * running, this Receiver will be notified, allowing us to re-register our Location Receivers
     * using the best available Location Provider is still available.
     */
    protected BroadcastReceiver locationProviderDisabledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean providerDisabled = !intent.getBooleanExtra(
                    LocationManager.KEY_PROVIDER_ENABLED, false);
            // Re-register the location listeners using the best available
            // Location Provider.
            if (providerDisabled) {
                disableLocationUpdates(false);
                requestLocationUpdates(context, null);
            }
        }
    };

    /**
     * If the battery state is low disable the passive location update receiver.
     */
    protected BroadcastReceiver refreshLocationUpdatesReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            disableLocationUpdates(false);
            requestLocationUpdates(context, null);
        }
    };

    after(Context context, IgnitedLocationActivity ignitedAnnotation) :
        execution(* Activity.onCreate(..)) && this(context)
        && @this(ignitedAnnotation) && within(@IgnitedLocationActivity *) {

        // Get a reference to the Context
        this.context = context;
        // Set pref file
        prefs = context.getSharedPreferences(IgnitedLocationConstants.SHARED_PREFERENCE_FILE,
                Context.MODE_PRIVATE);
        // Get references to the managers
        locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        handler = new Handler();

        // Specify the Criteria to use when requesting location updates while
        // the application is Active
        if (defaultCriteria == null) {
            defaultCriteria = new Criteria();
        }
        // Use gps if it's enabled and if battery level is at least 15%
        boolean useGps = prefs.getBoolean(IgnitedLocationConstants.SP_KEY_LOCATION_UPDATES_USE_GPS,
                IgnitedLocationConstants.USE_GPS_DEFAULT);
        if (useGps) {
            defaultCriteria.setAccuracy(Criteria.ACCURACY_FINE);
        } else {
            defaultCriteria.setPowerRequirement(Criteria.POWER_LOW);
        }

        // Setup the location update Pending Intent
        Intent activeIntent = new Intent(IgnitedLocationConstants.ACTIVE_LOCATION_UPDATE_ACTION);
        locationListenerPendingIntent = PendingIntent.getBroadcast(context, 0, activeIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        // Setup the passive location update Pending Intent
        Intent passiveIntent = new Intent(context, IgnitedPassiveLocationChangedReceiver.class);
        locationListenerPassivePendingIntent = PendingIntent.getBroadcast(context, 0,
                passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        // Instantiate a Location Update Requester class based on the available
        // platform version. This will be used to request location updates.
        locationUpdateRequester = PlatformSpecificImplementationFactory
                .getLocationUpdateRequester(context);
    }

    private boolean isBatteryLevelOk() {
        IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent intent = context.registerReceiver(null, filter);
        double currentLevel = 100.0;
        if (intent != null) {
            currentLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
        }

        return currentLevel >= prefs.getInt(IgnitedLocationConstants.SP_KEY_MIN_BATTERY_LEVEL,
                IgnitedLocationConstants.MIN_BATTERY_LEVEL_FOR_GPS_DEFAULT);
    }

    before(Context context, IgnitedLocationActivity ignitedAnnotation) :
        execution(* Activity.onResume(..)) && this(context)
        && @this(ignitedAnnotation) && within(@IgnitedLocationActivity *) {
        // Get a reference to the Context if this context is null
        if (this.context == null) {
            this.context = context;
        }

        saveToPreferences(context, ignitedAnnotation);

        Log.d(LOG_TAG, "Retrieving last known location...");
        // Get the last known location. This isn't directly affecting the UI, so put it on a
        // worker thread.
        ignitedLastKnownLocationTask = new IgnitedLastKnownLocationAsyncTask(context,
                locationUpdatesDistanceDiff, locationUpdatesInterval);
        if(IgnitedDiagnostics.SUPPORTS_HONEYCOMB) {
            ignitedLastKnownLocationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Boolean[0]);
        } else {
            ignitedLastKnownLocationTask.execute();
        }
    }

    /**
     * Save last settings to preferences.
     *
     * @param context
     * @param locationAnnotation
     */
    private void saveToPreferences(Context context, IgnitedLocationActivity locationAnnotation) {
        requestLocationUpdates = locationAnnotation.requestLocationUpdates();
        locationUpdatesDistanceDiff = locationAnnotation.locationUpdatesDistanceDiff();
        locationUpdatesInterval = locationAnnotation.locationUpdatesInterval();
        passiveLocationUpdatesDistanceDiff = locationAnnotation
                .passiveLocationUpdatesDistanceDiff();
        passiveLocationUpdatesInterval = locationAnnotation.passiveLocationUpdatesInterval();
        boolean enablePassiveLocationUpdates = locationAnnotation.enablePassiveUpdates();
        boolean useGps = locationAnnotation.useGps();

        Editor editor = prefs.edit();
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_ENABLE_LOCATION_UPDATES,
                requestLocationUpdates);
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_ENABLE_PASSIVE_LOCATION_UPDATES,
                enablePassiveLocationUpdates);
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_LOCATION_UPDATES_USE_GPS, useGps);
        editor.putInt(IgnitedLocationConstants.SP_KEY_LOCATION_UPDATES_DISTANCE_DIFF,
                locationUpdatesDistanceDiff);
        editor.putLong(IgnitedLocationConstants.SP_KEY_LOCATION_UPDATES_INTERVAL,
                locationUpdatesInterval);
        editor.putInt(IgnitedLocationConstants.SP_KEY_PASSIVE_LOCATION_UPDATES_DISTANCE_DIFF,
                passiveLocationUpdatesDistanceDiff);
        editor.putLong(IgnitedLocationConstants.SP_KEY_PASSIVE_LOCATION_UPDATES_INTERVAL,
                passiveLocationUpdatesInterval);
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_RUN_ONCE, true);
        editor.putInt(IgnitedLocationConstants.SP_KEY_MIN_BATTERY_LEVEL,
                locationAnnotation.minBatteryLevelForGps());
        editor.putLong(IgnitedLocationConstants.SP_KEY_WAIT_FOR_GPS_FIX_INTERVAL,
                locationAnnotation.waitForGpsFixInterval());
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_SHOW_WAIT_FOR_LOCATION_DIALOG,
                locationAnnotation.showWaitForLocationDialog());
        editor.commit();

    }

    before(Activity activity, IgnitedLocationActivity ignitedAnnotation) : execution(* Activity.onPause(..))
        && @this(ignitedAnnotation) && this(activity) && within(@IgnitedLocationActivity *) {

        if (ignitedAnnotation.requestLocationUpdates()) {
            disableLocationUpdates(true);
            handler.removeCallbacks(removeGpsUpdates);
        }

        if (ignitedLastKnownLocationTask != null) {
            if (ignitedLastKnownLocationTask.getStatus() != AsyncTask.Status.FINISHED) {
                Log.d(LOG_TAG, "Cancel last location task");
                ignitedLastKnownLocationTask.cancel(true);
            }
            ignitedLastKnownLocationTask.getLastLocationFinder().cancel();
        }

        boolean finishing = activity.isFinishing();
        if (finishing) {
            context = null;
            // Be sure to reset every flag previously set (since an aspect is a
            // singleton by default, so its state will be shared across all Activities that
            // reference it).
            requestLocationUpdates = false;
            locationUpdatesDisabled = true;
            waitForFixDialogShown = false;
            noProvidersEnabledDialogShown = false;
            locationProviderDisabledReceiverRegistered = false;
            refreshLocationUpdatesReceiverRegistered = false;
        }
    }

    Location around() : get(@IgnitedLocation Location *) {
        return currentLocation;
    }

    void around(Location freshLocation) : set(@IgnitedLocation Location *) && args(freshLocation)
        && within(IgnitedPassiveLocationChangedReceiver) && !adviceexecution() {

        currentLocation = freshLocation;
        Log.d(LOG_TAG, "New location from " + currentLocation.getProvider() + " (lat, lng/acc): "
                + currentLocation.getLatitude() + ", " + currentLocation.getLongitude() + "/"
                + currentLocation.getAccuracy());
    }

    void around(Location freshLocation) : set(@IgnitedLocation Location *) && args(freshLocation)
        && (within(IgnitedLocationChangedReceiver) || within(IgnitedAbstractLastLocationFinder)
                || within(IgnitedLastKnownLocationAsyncTask)) && !adviceexecution() {

        if (context == null) {
            return;
        }

        final Activity activity = (Activity) context;
        if (IgnitedLocationSupport.getEnabledProviders(context).isEmpty()) {
            // On some older versions of Android if a dialog is not shown by the activity after
            // calling showDialog an IllegalArgunmentException is raised. Catch this exception since
            // the docs returning a null dialog should be allowed.
            try {
                activity.showDialog(R.id.ign_loc_dialog_no_providers_enabled);
                noProvidersEnabledDialogShown = true;
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            return;
        }

        if (freshLocation == null) {
            // TODO Migrate this to DialogFragment at some point
            boolean showWaitForLocationDialog = prefs.getBoolean(
                    IgnitedLocationConstants.SP_KEY_SHOW_WAIT_FOR_LOCATION_DIALOG,
                    IgnitedLocationConstants.SHOW_WAIT_FOR_LOCATION_DIALOG_DEFAULT);
            if (showWaitForLocationDialog && !activity.isFinishing()) {
                // On some older versions of Android if a dialog is not shown by the activity after
                // calling showDialog an IllegalArgunmentException is raised. Catch this exception since
                // the docs returning a null dialog should be allowed.
                try {
                    activity.showDialog(R.id.ign_loc_dialog_wait_for_fix);
                    waitForFixDialogShown = true;
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
            return;
        }

        currentLocation = freshLocation;
        Log.d(LOG_TAG, "New location from " + currentLocation.getProvider() + " (lat, lng/acc): "
                + currentLocation.getLatitude() + ", " + currentLocation.getLongitude() + "/" + currentLocation.getAccuracy());
        // TODO Migrate this to DialogFragment at some point
        if (noProvidersEnabledDialogShown) {
            activity.removeDialog(R.id.ign_loc_dialog_no_providers_enabled);
            noProvidersEnabledDialogShown = false;
        } else if (waitForFixDialogShown) {
            activity.removeDialog(R.id.ign_loc_dialog_wait_for_fix);
            waitForFixDialogShown = false;
        }
        boolean keepRequestingLocationUpdates = ((OnIgnitedLocationChangedListener) context)
                .onIgnitedLocationChanged(currentLocation);
        Bundle extras = freshLocation.getExtras();
        // a) If location updates shouldn't be requested anymore turn them off.
        // b) Don't turn location updates on if last location is too old, since the single location
        // update is running.
        if (!keepRequestingLocationUpdates) {
            disableLocationUpdates(true);
            // PlatformSpecificImplementationFactory.getLastLocationFinder(context).cancel();
            return;
        } else if (requestLocationUpdates
                && (extras == null || !extras.containsKey(ILastLocationFinder.LAST_LOCATION_TOO_OLD_OR_INACCURATE_EXTRA))) {
            // If we requested location updates, turn them on here.
            requestLocationUpdates(context, null);
        }

        // If gps is enabled location comes from gps, remove runnable that removes gps updates
        boolean lastLocation = extras != null && extras.containsKey(IgnitedLocationConstants.IGNITED_LAST_LOCATION_EXTRA);
        if (!lastLocation && defaultCriteria.getAccuracy() == Criteria.ACCURACY_FINE
                && currentLocation.getProvider().equals(LocationManager.GPS_PROVIDER)) {
            handler.removeCallbacks(removeGpsUpdates);
        }
    }

    /**
     * Start listening for location updates.
     */
    protected void requestLocationUpdates(Context context, Criteria criteria) {
        if (!locationUpdatesDisabled) {
            return;
        }
        Criteria locationUpdateCriteria = criteria;
        if (criteria == null) {
            if (isBatteryLevelOk()) {
                locationUpdateCriteria = defaultCriteria;
            } else {
                locationUpdateCriteria = lowPowerCriteria();
            }
        }
        Log.d(LOG_TAG, "Disabling passive location updates");
        locationManager.removeUpdates(locationListenerPassivePendingIntent);

        Log.d(LOG_TAG, "Requesting location updates");
        // Normal updates while activity is visible.
        locationUpdateRequester.requestLocationUpdates(locationUpdatesInterval,
                locationUpdatesDistanceDiff, locationUpdateCriteria, locationListenerPendingIntent);

        // Register a receiver that listens for when the provider I'm using has
        // been disabled.
        IntentFilter locationProviderDisabledIntentFilter = new IntentFilter(
                IgnitedLocationConstants.ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED_ACTION);
        context.registerReceiver(locationProviderDisabledReceiver,
                locationProviderDisabledIntentFilter);
        locationProviderDisabledReceiverRegistered = true;

        IntentFilter refreshLocationUpdatesIntentFilter = new IntentFilter(
                IgnitedLocationConstants.UPDATE_LOCATION_UPDATES_CRITERIA_ACTION);
        context.registerReceiver(refreshLocationUpdatesReceiver, refreshLocationUpdatesIntentFilter);
        refreshLocationUpdatesReceiverRegistered = true;

        // Register a receiver that listens for when a better provider than I'm
        // using becomes available.
        String bestProvider = locationManager.getBestProvider(locationUpdateCriteria, false);
        String bestAvailableProvider = locationManager.getBestProvider(locationUpdateCriteria, true);
        if (bestProvider != null && !bestProvider.equals(bestAvailableProvider)) {
            bestInactiveLocationProviderListener = new IgnitedLocationListener(context);
            locationManager.requestLocationUpdates(bestProvider, 0, 0,
                    bestInactiveLocationProviderListener, context.getMainLooper());
        }

        if (bestAvailableProvider.equals(LocationManager.GPS_PROVIDER)) {
            Log.d(LOG_TAG, "Posting delayed remove GPS updates message");
            // Post a runnable that will remove gps updates if no gps location is returned after 1
            // minute in order to avoid draining the battery.
            handler.postDelayed(removeGpsUpdates, prefs.getLong(
                    IgnitedLocationConstants.SP_KEY_WAIT_FOR_GPS_FIX_INTERVAL,
                    IgnitedLocationConstants.WAIT_FOR_GPS_FIX_INTERVAL_DEFAULT));
        }

        locationUpdatesDisabled = false;
    }

    /**
     * Stop listening for location updates
     *
     * @param enablePassiveLocationUpdates
     */
    protected void disableLocationUpdates(boolean requestPassiveLocationUpdates) {
        if (locationUpdatesDisabled) {
            return;
        }

        Log.d(LOG_TAG, "Disabling location updates");
        if (locationProviderDisabledReceiverRegistered) {
            context.unregisterReceiver(locationProviderDisabledReceiver);
            locationProviderDisabledReceiverRegistered = false;
        }
        if (refreshLocationUpdatesReceiverRegistered) {
            context.unregisterReceiver(refreshLocationUpdatesReceiver);
            refreshLocationUpdatesReceiverRegistered = false;
        }
        locationUpdateRequester.removeLocationUpdates();
        if (bestInactiveLocationProviderListener != null) {
            locationManager.removeUpdates(bestInactiveLocationProviderListener);
        }

        boolean finishing = ((Activity) context).isFinishing();

        if (requestPassiveLocationUpdates && !finishing) {
            requestPassiveLocationUpdates();
        }

        locationUpdatesDisabled = true;
    }

    private void requestPassiveLocationUpdates() {
        if (IgnitedDiagnostics.SUPPORTS_FROYO
                && prefs.getBoolean(
                        IgnitedLocationConstants.SP_KEY_ENABLE_PASSIVE_LOCATION_UPDATES,
                        IgnitedLocationConstants.ENABLE_PASSIVE_LOCATION_UPDATES_DEFAULT)) {
            Log.d(LOG_TAG, "Requesting passive location updates");
            // Passive location updates from 3rd party apps when the Activity isn't
            // visible. Only for Android 2.2+.
            locationUpdateRequester.requestPassiveLocationUpdates(passiveLocationUpdatesInterval,
                    passiveLocationUpdatesDistanceDiff, locationListenerPassivePendingIntent);
        }
    }

    public boolean isLocationUpdatesDisabled() {
        return locationUpdatesDisabled;
    }

    public Criteria lowPowerCriteria() {
        if (lowPowerCriteria == null) {
            lowPowerCriteria = new Criteria();
            lowPowerCriteria.setPowerRequirement(Criteria.POWER_LOW);
            lowPowerCriteria.setAccuracy(Criteria.NO_REQUIREMENT);
        }
        return lowPowerCriteria;
    }

    /**
     * If the best Location Provider (usually GPS) is not available when we request location
     * updates, this listener will be notified if / when it becomes available. It calls
     * requestLocationUpdates to re-register the location listeners using the better Location
     * Provider.
     */
    private class IgnitedLocationListener implements LocationListener {
        private Context context;

        public IgnitedLocationListener(Context appContext) {
            this.context = appContext;
        }

        @Override
        public void onLocationChanged(Location l) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
            // Re-register the location listeners using the better Location
            // Provider.
            disableLocationUpdates(false);
            requestLocationUpdates(context, null);
        }
    }

}

/*
 * Copyright 2011 Google Inc.
 *
 * 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.
 *
 * This code has been modified by Stefano Dacchille.
 */

package com.github.ignition.location;

import org.aspectj.lang.annotation.SuppressAjWarnings;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;

import com.github.ignition.location.annotations.IgnitedLocation;
import com.github.ignition.location.annotations.IgnitedLocationActivity;
import com.github.ignition.location.receivers.IgnitedLocationChangedReceiver;
import com.github.ignition.location.receivers.IgnitedPassiveLocationChangedReceiver;
import com.github.ignition.location.tasks.IgnitedLastKnownLocationAsyncTask;
import com.github.ignition.location.templates.ILastLocationFinder;
import com.github.ignition.location.templates.IgnitedAbstractLastLocationFinder;
import com.github.ignition.location.templates.IgnitedAbstractLocationUpdateRequester;
import com.github.ignition.location.templates.OnIgnitedLocationChangedListener;
import com.github.ignition.location.utils.IgnitedLocationSupport;
import com.github.ignition.location.utils.PlatformSpecificImplementationFactory;
import com.github.ignition.support.IgnitedDiagnostics;

@SuppressAjWarnings
public aspect IgnitedLocationManager {
    public static final String LOG_TAG = IgnitedLocationManager.class.getSimpleName();

    declare parents : (@IgnitedLocationActivity *) implements OnIgnitedLocationChangedListener;

    private Criteria defaultCriteria, lowPowerCriteria;
    protected IgnitedAbstractLocationUpdateRequester locationUpdateRequester;
    protected PendingIntent locationListenerPendingIntent, locationListenerPassivePendingIntent;
    protected LocationManager locationManager;
    protected IgnitedLocationListener bestInactiveLocationProviderListener;

    private Context context;
    private volatile Location currentLocation;

    private IgnitedLastKnownLocationAsyncTask ignitedLastKnownLocationTask;
    private SharedPreferences prefs;
    private Handler handler;

    private long locationUpdatesInterval, passiveLocationUpdatesInterval;
    private int locationUpdatesDistanceDiff;
    private int passiveLocationUpdatesDistanceDiff;
    private boolean requestLocationUpdates = false;
    private boolean locationUpdatesDisabled = true;
    private boolean waitForFixDialogShown = false;
    private boolean noProvidersEnabledDialogShown = false;
    private boolean locationProviderDisabledReceiverRegistered = false;
    private boolean refreshLocationUpdatesReceiverRegistered = false;

    // Switch to another provider if gps doesn't return a location quickly enough.
    private Runnable removeGpsUpdates = new Runnable() {
        @Override
        public void run() {
            Log.d(LOG_TAG,
                    "It looks like GPS isn't available at this time (i.e.: maybe you're indoors). Removing GPS location updates and requesting network updates.");

            disableLocationUpdates(false);
            requestLocationUpdates(context, lowPowerCriteria());
        }
    };

    /**
     * If the Location Provider we're using to receive location updates is disabled while the app is
     * running, this Receiver will be notified, allowing us to re-register our Location Receivers
     * using the best available Location Provider is still available.
     */
    protected BroadcastReceiver locationProviderDisabledReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean providerDisabled = !intent.getBooleanExtra(
                    LocationManager.KEY_PROVIDER_ENABLED, false);
            // Re-register the location listeners using the best available
            // Location Provider.
            if (providerDisabled) {
                disableLocationUpdates(false);
                requestLocationUpdates(context, null);
            }
        }
    };

    /**
     * If the battery state is low disable the passive location update receiver.
     */
    protected BroadcastReceiver refreshLocationUpdatesReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            disableLocationUpdates(false);
            requestLocationUpdates(context, null);
        }
    };

    after(Context context, IgnitedLocationActivity ignitedAnnotation) :
        execution(* Activity.onCreate(..)) && this(context)
        && @this(ignitedAnnotation) && within(@IgnitedLocationActivity *) {

        // Get a reference to the Context
        this.context = context;
        // Set pref file
        prefs = context.getSharedPreferences(IgnitedLocationConstants.SHARED_PREFERENCE_FILE,
                Context.MODE_PRIVATE);
        // Get references to the managers
        locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        handler = new Handler();

        // Specify the Criteria to use when requesting location updates while
        // the application is Active
        if (defaultCriteria == null) {
            defaultCriteria = new Criteria();
        }
        // Use gps if it's enabled and if battery level is at least 15%
        boolean useGps = prefs.getBoolean(IgnitedLocationConstants.SP_KEY_LOCATION_UPDATES_USE_GPS,
                IgnitedLocationConstants.USE_GPS_DEFAULT);
        if (useGps) {
            defaultCriteria.setAccuracy(Criteria.ACCURACY_FINE);
        } else {
            defaultCriteria.setPowerRequirement(Criteria.POWER_LOW);
        }

        // Setup the location update Pending Intent
        Intent activeIntent = new Intent(IgnitedLocationConstants.ACTIVE_LOCATION_UPDATE_ACTION);
        locationListenerPendingIntent = PendingIntent.getBroadcast(context, 0, activeIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        // Setup the passive location update Pending Intent
        Intent passiveIntent = new Intent(context, IgnitedPassiveLocationChangedReceiver.class);
        locationListenerPassivePendingIntent = PendingIntent.getBroadcast(context, 0,
                passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        // Instantiate a Location Update Requester class based on the available
        // platform version. This will be used to request location updates.
        locationUpdateRequester = PlatformSpecificImplementationFactory
                .getLocationUpdateRequester(context);
    }

    private boolean isBatteryOk() {
        IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent intent = context.registerReceiver(null, filter);
        double currentLevel = 100.0;
        if (intent != null) {
            currentLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
        }

        return currentLevel >= prefs.getInt(IgnitedLocationConstants.SP_KEY_MIN_BATTERY_LEVEL,
                IgnitedLocationConstants.MIN_BATTERY_LEVEL_FOR_GPS_DEFAULT);
    }

    before(Context context, IgnitedLocationActivity ignitedAnnotation) :
        execution(* Activity.onResume(..)) && this(context)
        && @this(ignitedAnnotation) && within(@IgnitedLocationActivity *) {
        // Get a reference to the Context if this context is null
        if (this.context == null) {
            this.context = context;
        }

        saveToPreferences(context, ignitedAnnotation);

        Log.d(LOG_TAG, "Retrieving last known location...");
        // Get the last known location. This isn't directly affecting the UI, so put it on a
        // worker thread.
        ignitedLastKnownLocationTask = new IgnitedLastKnownLocationAsyncTask(context,
                locationUpdatesDistanceDiff, locationUpdatesInterval);
        if(IgnitedDiagnostics.SUPPORTS_HONEYCOMB) {
            ignitedLastKnownLocationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Boolean[0]);
        } else {
            ignitedLastKnownLocationTask.execute();
        }
    }

    /**
     * Save last settings to preferences.
     *
     * @param context
     * @param locationAnnotation
     */
    private void saveToPreferences(Context context, IgnitedLocationActivity locationAnnotation) {
        requestLocationUpdates = locationAnnotation.requestLocationUpdates();
        locationUpdatesDistanceDiff = locationAnnotation.locationUpdatesDistanceDiff();
        locationUpdatesInterval = locationAnnotation.locationUpdatesInterval();
        passiveLocationUpdatesDistanceDiff = locationAnnotation
                .passiveLocationUpdatesDistanceDiff();
        passiveLocationUpdatesInterval = locationAnnotation.passiveLocationUpdatesInterval();
        boolean enablePassiveLocationUpdates = locationAnnotation.enablePassiveUpdates();
        boolean useGps = locationAnnotation.useGps();

        Editor editor = prefs.edit();
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_ENABLE_LOCATION_UPDATES,
                requestLocationUpdates);
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_ENABLE_PASSIVE_LOCATION_UPDATES,
                enablePassiveLocationUpdates);
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_LOCATION_UPDATES_USE_GPS, useGps);
        editor.putInt(IgnitedLocationConstants.SP_KEY_LOCATION_UPDATES_DISTANCE_DIFF,
                locationUpdatesDistanceDiff);
        editor.putLong(IgnitedLocationConstants.SP_KEY_LOCATION_UPDATES_INTERVAL,
                locationUpdatesInterval);
        editor.putInt(IgnitedLocationConstants.SP_KEY_PASSIVE_LOCATION_UPDATES_DISTANCE_DIFF,
                passiveLocationUpdatesDistanceDiff);
        editor.putLong(IgnitedLocationConstants.SP_KEY_PASSIVE_LOCATION_UPDATES_INTERVAL,
                passiveLocationUpdatesInterval);
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_RUN_ONCE, true);
        editor.putInt(IgnitedLocationConstants.SP_KEY_MIN_BATTERY_LEVEL,
                locationAnnotation.minBatteryLevelForGps());
        editor.putLong(IgnitedLocationConstants.SP_KEY_WAIT_FOR_GPS_FIX_INTERVAL,
                locationAnnotation.waitForGpsFixInterval());
        editor.putBoolean(IgnitedLocationConstants.SP_KEY_SHOW_WAIT_FOR_LOCATION_DIALOG,
                locationAnnotation.showWaitForLocationDialog());
        editor.commit();

    }

    before(Activity activity, IgnitedLocationActivity ignitedAnnotation) : execution(* Activity.onPause(..))
        && @this(ignitedAnnotation) && this(activity) && within(@IgnitedLocationActivity *) {

        if (ignitedAnnotation.requestLocationUpdates()) {
            disableLocationUpdates(true);
            handler.removeCallbacks(removeGpsUpdates);
        }

        if (ignitedLastKnownLocationTask != null) {
            if (ignitedLastKnownLocationTask.getStatus() != AsyncTask.Status.FINISHED) {
                Log.d(LOG_TAG, "Cancel last location task");
                ignitedLastKnownLocationTask.cancel(true);
            }
            ignitedLastKnownLocationTask.getLastLocationFinder().cancel();
        }

        boolean finishing = activity.isFinishing();
        if (finishing) {
            context = null;
            // Be sure to reset every flag previously set (since an aspect is a
            // singleton by default, so its state will be shared across all Activities that
            // reference it).
            requestLocationUpdates = false;
            locationUpdatesDisabled = true;
            waitForFixDialogShown = false;
            noProvidersEnabledDialogShown = false;
            locationProviderDisabledReceiverRegistered = false;
            refreshLocationUpdatesReceiverRegistered = false;
        }
    }

    Location around() : get(@IgnitedLocation Location *) {
        return currentLocation;
    }

    void around(Location freshLocation) : set(@IgnitedLocation Location *) && args(freshLocation)
        && within(IgnitedPassiveLocationChangedReceiver) && !adviceexecution() {

        currentLocation = freshLocation;
        Log.d(LOG_TAG, "New location from " + currentLocation.getProvider() + " (lat, lng/acc): "
                + currentLocation.getLatitude() + ", " + currentLocation.getLongitude() + "/"
                + currentLocation.getAccuracy());
    }

    void around(Location freshLocation) : set(@IgnitedLocation Location *) && args(freshLocation)
        && (within(IgnitedLocationChangedReceiver) || within(IgnitedAbstractLastLocationFinder)
                || within(IgnitedLastKnownLocationAsyncTask)) && !adviceexecution() {

        if (context == null) {
            return;
        }

        final Activity activity = (Activity) context;
        if (IgnitedLocationSupport.getEnabledProviders(context).isEmpty()) {
            // On some older versions of Android if a dialog is not shown by the activity after
            // calling showDialog an IllegalArgunmentException is raised. Catch this exception since
            // the docs returning a null dialog should be allowed.
            try {
                activity.showDialog(R.id.ign_loc_dialog_no_providers_enabled);
                noProvidersEnabledDialogShown = true;
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            }
            return;
        }

        if (freshLocation == null) {
            // TODO Migrate this to DialogFragment at some point
            boolean showWaitForLocationDialog = prefs.getBoolean(
                    IgnitedLocationConstants.SP_KEY_SHOW_WAIT_FOR_LOCATION_DIALOG,
                    IgnitedLocationConstants.SHOW_WAIT_FOR_LOCATION_DIALOG_DEFAULT);
            if (showWaitForLocationDialog && !activity.isFinishing()) {
                // On some older versions of Android if a dialog is not shown by the activity after
                // calling showDialog an IllegalArgunmentException is raised. Catch this exception since
                // the docs returning a null dialog should be allowed.
                try {
                    activity.showDialog(R.id.ign_loc_dialog_wait_for_fix);
                    waitForFixDialogShown = true;
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
            return;
        }

        currentLocation = freshLocation;
        Log.d(LOG_TAG, "New location from " + currentLocation.getProvider() + " (lat, lng/acc): "
                + currentLocation.getLatitude() + ", " + currentLocation.getLongitude() + "/" + currentLocation.getAccuracy());
        // TODO Migrate this to DialogFragment at some point
        if (noProvidersEnabledDialogShown) {
            activity.removeDialog(R.id.ign_loc_dialog_no_providers_enabled);
            noProvidersEnabledDialogShown = false;
        } else if (waitForFixDialogShown) {
            activity.removeDialog(R.id.ign_loc_dialog_wait_for_fix);
            waitForFixDialogShown = false;
        }
        boolean keepRequestingLocationUpdates = ((OnIgnitedLocationChangedListener) context)
                .onIgnitedLocationChanged(currentLocation);
        Bundle extras = freshLocation.getExtras();
        // a) If location updates shouldn't be requested anymore turn them off.
        // b) Don't turn location updates on if last location is too old, since the single location
        // update is running.
        if (!keepRequestingLocationUpdates) {
            disableLocationUpdates(true);
            // PlatformSpecificImplementationFactory.getLastLocationFinder(context).cancel();
            return;
        } else if (requestLocationUpdates
                && (extras == null || !extras.containsKey(ILastLocationFinder.LAST_LOCATION_TOO_OLD_OR_INACCURATE_EXTRA))) {
            // If we requested location updates, turn them on here.
            requestLocationUpdates(context, null);
        }

        // If gps is enabled location comes from gps, remove runnable that removes gps updates
        boolean lastLocation = extras != null && extras.containsKey(IgnitedLocationConstants.IGNITED_LAST_LOCATION_EXTRA);
        if (!lastLocation && defaultCriteria.getAccuracy() == Criteria.ACCURACY_FINE
                && currentLocation.getProvider().equals(LocationManager.GPS_PROVIDER)) {
            handler.removeCallbacks(removeGpsUpdates);
        }
    }

    /**
     * Start listening for location updates.
     */
    protected void requestLocationUpdates(Context context, Criteria criteria) {
        if (!locationUpdatesDisabled) {
            return;
        }
        Criteria locationUpdateCriteria = criteria;
        if (criteria == null) {
            if (isBatteryOk()) {
                locationUpdateCriteria = defaultCriteria;
            } else {
                locationUpdateCriteria = lowPowerCriteria();
            }
        }
        Log.d(LOG_TAG, "Disabling passive location updates");
        locationManager.removeUpdates(locationListenerPassivePendingIntent);

        Log.d(LOG_TAG, "Requesting location updates");
        // Normal updates while activity is visible.
        locationUpdateRequester.requestLocationUpdates(locationUpdatesInterval,
                locationUpdatesDistanceDiff, locationUpdateCriteria, locationListenerPendingIntent);

        // Register a receiver that listens for when the provider I'm using has
        // been disabled.
        IntentFilter locationProviderDisabledIntentFilter = new IntentFilter(
                IgnitedLocationConstants.ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED_ACTION);
        context.registerReceiver(locationProviderDisabledReceiver,
                locationProviderDisabledIntentFilter);
        locationProviderDisabledReceiverRegistered = true;

        IntentFilter refreshLocationUpdatesIntentFilter = new IntentFilter(
                IgnitedLocationConstants.UPDATE_LOCATION_UPDATES_CRITERIA_ACTION);
        context.registerReceiver(refreshLocationUpdatesReceiver, refreshLocationUpdatesIntentFilter);
        refreshLocationUpdatesReceiverRegistered = true;

        // Register a receiver that listens for when a better provider than I'm
        // using becomes available.
        String bestProvider = locationManager.getBestProvider(locationUpdateCriteria, false);
        String bestAvailableProvider = locationManager.getBestProvider(locationUpdateCriteria, true);
        if (bestProvider != null && !bestProvider.equals(bestAvailableProvider)) {
            bestInactiveLocationProviderListener = new IgnitedLocationListener(context);
            locationManager.requestLocationUpdates(bestProvider, 0, 0,
                    bestInactiveLocationProviderListener, context.getMainLooper());
        }

        if (bestAvailableProvider.equals(LocationManager.GPS_PROVIDER)) {
            Log.d(LOG_TAG, "Posting delayed remove GPS updates message");
            // Post a runnable that will remove gps updates if no gps location is returned after 1
            // minute in order to avoid draining the battery.
            handler.postDelayed(removeGpsUpdates, prefs.getLong(
                    IgnitedLocationConstants.SP_KEY_WAIT_FOR_GPS_FIX_INTERVAL,
                    IgnitedLocationConstants.WAIT_FOR_GPS_FIX_INTERVAL_DEFAULT));
        }

        locationUpdatesDisabled = false;
    }

    /**
     * Stop listening for location updates
     *
     * @param enablePassiveLocationUpdates
     */
    protected void disableLocationUpdates(boolean requestPassiveLocationUpdates) {
        if (locationUpdatesDisabled) {
            return;
        }

        Log.d(LOG_TAG, "Disabling location updates");
        if (locationProviderDisabledReceiverRegistered) {
            context.unregisterReceiver(locationProviderDisabledReceiver);
            locationProviderDisabledReceiverRegistered = false;
        }
        if (refreshLocationUpdatesReceiverRegistered) {
            context.unregisterReceiver(refreshLocationUpdatesReceiver);
            refreshLocationUpdatesReceiverRegistered = false;
        }
        locationUpdateRequester.removeLocationUpdates();
        if (bestInactiveLocationProviderListener != null) {
            locationManager.removeUpdates(bestInactiveLocationProviderListener);
        }

        boolean finishing = ((Activity) context).isFinishing();

        if (requestPassiveLocationUpdates && !finishing) {
            requestPassiveLocationUpdates();
        }

        locationUpdatesDisabled = true;
    }

    private void requestPassiveLocationUpdates() {
        if (IgnitedDiagnostics.SUPPORTS_FROYO
                && prefs.getBoolean(
                        IgnitedLocationConstants.SP_KEY_ENABLE_PASSIVE_LOCATION_UPDATES,
                        IgnitedLocationConstants.ENABLE_PASSIVE_LOCATION_UPDATES_DEFAULT)) {
            Log.d(LOG_TAG, "Requesting passive location updates");
            // Passive location updates from 3rd party apps when the Activity isn't
            // visible. Only for Android 2.2+.
            locationUpdateRequester.requestPassiveLocationUpdates(passiveLocationUpdatesInterval,
                    passiveLocationUpdatesDistanceDiff, locationListenerPassivePendingIntent);
        }
    }

    public boolean isLocationUpdatesDisabled() {
        return locationUpdatesDisabled;
    }

    public Criteria lowPowerCriteria() {
        if (lowPowerCriteria == null) {
            lowPowerCriteria = new Criteria();
            lowPowerCriteria.setPowerRequirement(Criteria.POWER_LOW);
            lowPowerCriteria.setAccuracy(Criteria.NO_REQUIREMENT);
        }
        return lowPowerCriteria;
    }

    /**
     * If the best Location Provider (usually GPS) is not available when we request location
     * updates, this listener will be notified if / when it becomes available. It calls
     * requestLocationUpdates to re-register the location listeners using the better Location
     * Provider.
     */
    private class IgnitedLocationListener implements LocationListener {
        private Context context;

        public IgnitedLocationListener(Context appContext) {
            this.context = appContext;
        }

        @Override
        public void onLocationChanged(Location l) {
        }

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }

        @Override
        public void onProviderEnabled(String provider) {
            // Re-register the location listeners using the better Location
            // Provider.
            disableLocationUpdates(false);
            requestLocationUpdates(context, null);
        }
    }

}


re-adding AspectJ support; softening IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jfs/mechjack.git/'


Dispatcher monitor

Dispatcher monitor

package org.eigengo.monitor.agent.akka;

public aspect DispatcherMonitoringAspect extends AbstractMonitoringAspect {

}

error: pathspec 'agent-akka/src/main/aj/org/eigengo/monitor/agent/akka/DispatcherMonitoringAspect.aj' did not match any file(s) known to git


-solving bug

-solving bug

error: pathspec 'Muses' did not match any file(s) known to git
error: pathspec 'Sim/src/main/java/eu/musesproject/server/rt2ae/Accessrequest_Roo_Jpa_ActiveRecord.aj' did not match any file(s) known to git


Extra fixture for more complex execution path testing.

package damp.ekeko.aspectj.annasstests;

import damp.ekeko.aspectj.annotations.RequiresPrevious;

//testing advice execution order and execution paths through advice and methods
public aspect PrevFix2 {
	declare precedence: PrevFix, PrevFix2;

	//succeeds
	@RequiresPrevious("beforecompute")
	before() : call(int *.compute(String))
	{	}

	//succeeds
	@RequiresPrevious("beforecompute")
	after() : call(int *.compute(String))
	{	}

	//succeeds
	@RequiresPrevious("preparing")
	after() : call(int *.compute(String))
	{	}

	//succeeds
	@RequiresPrevious("beforecompute")
	after() : call(void *.simulate())
	{
		this.unthink();
	}

	@RequiresPrevious("thinking")
	void unthink()
	{ }
}

error: pathspec 'damp.ekeko.aspectj.plugin.test/resources/TestCases/AJ-LMP-Annotations/src/damp/ekeko/aspectj/annasstests/PrevFix2.aj' did not match any file(s) known to git


Instrumentation added for property Online 4-4 (JavaMOP)

package benchmark.competition.java.javaMOP.monitoring;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import monitoring.impl.MonitorFactory;
import monitoring.intf.Monitor;
import properties.Property;
import properties.competition.JavaMOP;
import structure.impl.other.Verdict;
import structure.intf.QEA;
import benchmark.competition.java.javaMOP.MapIteratorTest;

@SuppressWarnings("rawtypes")
public aspect JavaMOPFourAspect {

	private final Monitor monitor;

	private final int CREATE = 1;
	private final int ITERATOR = 2;
	private final int USE = 3;
	private final int UPDATE = 4;

	public JavaMOPFourAspect() {
		QEA qea = new JavaMOP().make(Property.JAVAMOP_FOUR);
		monitor = MonitorFactory.create(qea);
	}

	// create(m,c)
	pointcut create(Map map) : call(Set Map.keySet()) && target(map)
		&& within(MapIteratorTest);

	// iterator(c,i)
	pointcut iterator(Collection col) : call(Iterator Collection.iterator())
		&& target(col) && within(MapIteratorTest);

	// update(m)
	pointcut update(Map map) : call(* Map.put(*, *)) && target(map)
		&& within(MapIteratorTest);

	// use(i)
	pointcut use(Iterator iter) : call(* Iterator.*(..)) && target(iter)
		&& within(MapIteratorTest);

	after(Map map) returning (Collection col) : create(map) {
		Verdict verdict = monitor.step(CREATE, map, col);
		if (verdict == Verdict.FAILURE) {
			System.err.println("Violation in JavaMOP 4. [map=" + map + ", col="
					+ col + "]. UnsafeMapIterator");
			System.exit(0);
		}
	}

	after(Collection col) returning (Iterator iter) : iterator(col) {
		Verdict verdict = monitor.step(ITERATOR, col, iter);
		if (verdict == Verdict.FAILURE) {
			System.err.println("Violation in JavaMOP 4. [col=" + col
					+ ", iter=" + iter + "]. UnsafeMapIterator");
			System.exit(0);
		}
	}

	before(Map map) : update(map) {
		Verdict verdict = monitor.step(UPDATE, map);
		if (verdict == Verdict.FAILURE) {
			System.err.println("Violation in JavaMOP 4. [map=" + map
					+ "]. UnsafeMapIterator");
			System.exit(0);
		}
	}

	before(Iterator iter) : use(iter) {
		Verdict verdict = monitor.step(USE, iter);
		if (verdict == Verdict.FAILURE) {
			System.err.println("Violation in JavaMOP 4. [iter=" + iter
					+ "]. UnsafeMapIterator");
			System.exit(0);
		}
	}

	pointcut endOfProgram() : execution(void MapIteratorTest.main(String[]));

	after() : endOfProgram() {
		Verdict verdict = monitor.end();
		if (verdict == Verdict.FAILURE || verdict == Verdict.WEAK_FAILURE) {
			System.err.println("Violation in JavaMOP 4. UnsafeMapIterator.");
		} else {
			System.err.println("Property JavaMOP 4 satisfied");
		}
	}
}

error: pathspec 'code/qea/src/benchmark/competition/java/javaMOP/monitoring/JavaMOPFourAspect.aj' did not match any file(s) known to git


Add aspect to check environment variables for Baggage from main method

package edu.brown.cs.systems.tracing.aspects;

import edu.brown.cs.systems.baggage.BaggageUtils;

/**
 * Instruments all main methods
 */
public aspect TracingPlaneInit {

    declare precedence: TracingPlaneInit, *;

    before(): execution(public static void main(String[])) {
        BaggageUtils.checkEnvironment(System.getenv());
    }

}

error: pathspec 'tracingplane/aspects/src/main/aspect/edu/brown/cs/systems/tracing/aspects/TracingPlaneInit.aj' did not match any file(s) known to git


-solving bug

-solving bug

error: pathspec 'Muses' did not match any file(s) known to git
error: pathspec 'Sim/src/main/java/eu/musesproject/server/rt2ae/Opportunity_Roo_DbManaged.aj' did not match any file(s) known to git


Add a test cases for arrays in arrooj

Add a test cases for arrays in arrooj

// fails
// TYPE_MISMATCH

class Arrays {
  int array[][] = new int[3][];
  int array2[]  = {1, 2, 3, 4};
  int array3[]  = {1, "klj", 3, 4}; // fails

  void m() {
    int k = array[2][3];
    k     = array2[3];
  }
}

error: pathspec 'tests/arrooj/arrays.aj' did not match any file(s) known to git


txtUML, trunk: fix - previous commit did not add InstructionImporerAspect.aj to version control

package txtuml.importer;

import org.aspectj.lang.Signature;

import txtuml.api.ExternalClass;
import txtuml.api.ModelBool;
import txtuml.api.ModelClass;
import txtuml.api.ModelInt;
import txtuml.api.ModelString;
import txtuml.api.ExternalClass;
import txtuml.api.Association.AssociationEnd;

public privileged aspect InstructionImporterAspect extends AbstractImporterAspect {

	after() returning(ModelInt target) : call((ModelInt).new(int)) && isActive()
	{
		InstructionImporter.createModelTypeLiteral(target);
	}
	after() returning(ModelBool target) : call((ModelBool).new(boolean)) && isActive()
	{
		InstructionImporter.createModelTypeLiteral(target);
	}
	after() returning(ModelString target) : call((ModelString).new(String)) && isActive()
	{
		InstructionImporter.createModelTypeLiteral(target);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	Object around(AssociationEnd target):target(target) && call(ModelClass selectOne()) && isActive()
	{
		return InstructionImporter.importAssociationEnd_SelectOne(target);
	}

	after(ModelClass target): execution((ModelClass+).new(..)) && isActive() && target(target)
	{
		InstructionImporter.importInstanceCreation(target);
	}

	Object around(ModelClass target): target(target) && call(* *(..))  && isActive() {
		try
		{
			return InstructionImporter.importMethodCall(target, thisJoinPoint.getSignature().getName(),thisJoinPoint.getArgs());
		}
		catch(ImportException exc)
		{
			//exc.printStackTrace();
			return null;
		}
	}

	Object around(ExternalClass target) : target(target) && call(* (ExternalClass+).*(..)) && isActive() {
		return InstructionImporter.callExternal(target, thisJoinPoint.getSignature().getName(), thisJoinPoint.getArgs());
	}

	Object around() : call(static * (ExternalClass+).*(..)) && isActive() {
		return InstructionImporter.callStaticExternal(thisJoinPoint.getSignature().getDeclaringType(), thisJoinPoint.getSignature().getName(), thisJoinPoint.getArgs());
	}

	Object around(ModelClass target, Object newValue) : target(target) && set(* *) && args(newValue) && isActive() && !withincode((ModelClass+).new(..))
	{
		return InstructionImporter.fieldSet(target,thisJoinPoint.getSignature().getName(),newValue);
	}

	Object around(ModelClass target) : target(target) && get(* *) && isActive() {
		Signature signature=thisJoinPoint.getSignature();
		try {
			return InstructionImporter.fieldGet(target,signature.getName(),signature.getDeclaringType().getDeclaredField(signature.getName()).getType());
		} catch (NoSuchFieldException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
		return null;
	}
}

error: pathspec 'src/txtuml/importer/InstructionImporterAspect.aj' did not match any file(s) known to git


Instrumentation added for property Java 4-2 (JavaMOP)

package benchmark.competition.java.javaMOP.monitoring;

import java.util.concurrent.locks.Lock;

import monitoring.impl.MonitorFactory;
import monitoring.intf.Monitor;
import properties.Property;
import properties.competition.JavaMOP;
import structure.impl.other.Verdict;
import structure.intf.QEA;
import benchmark.competition.java.javaMOP.LockTest;

public aspect JavaMOPTwoAspect {

	private final Monitor monitor;

	private final int LOCK = 1;
	private final int UNLOCK = 2;

	public JavaMOPTwoAspect() {
		QEA qea = new JavaMOP().make(Property.JAVAMOP_TWO);
		monitor = MonitorFactory.create(qea);
	}

	pointcut lockPC(Thread thread, Lock lockObj) : call(void Lock.lock())
		&& target(lockObj) && this(thread);

	pointcut unlockPC(Thread thread, Lock lockObj) : call(void Lock.unlock())
		&& target(lockObj) && this(thread);

	before(Thread thread, Lock lockObj) : lockPC(thread, lockObj) {
		Verdict verdict = null;
		synchronized (monitor) {
			verdict = monitor.step(LOCK, thread, lockObj);
		}
		if (verdict == Verdict.FAILURE) {
			System.err
					.println("Violation in JavaMOP 2. [thread="
							+ thread
							+ ", lock="
							+ lockObj
							+ "]. A thread should release a lock as many times as it acquires the lock.");
		}
	}

	before(Thread thread, Lock lockObj) : unlockPC(thread, lockObj) {
		Verdict verdict = null;
		synchronized (monitor) {
			verdict = monitor.step(UNLOCK, thread, lockObj);
		}
		if (verdict == Verdict.FAILURE) {
			System.err
					.println("Violation in JavaMOP 2. [thread="
							+ thread
							+ ", lock="
							+ lockObj
							+ "]. A thread should release a lock as many times as it acquires the lock.");
		}
	}

	pointcut endOfProgram() : execution(void LockTest.main(String[]));

	after() : endOfProgram() {
		Verdict verdict = monitor.end();
		if (verdict == Verdict.FAILURE || verdict == Verdict.WEAK_FAILURE) {
			System.err
					.println("Violation in JavaMOP 2. A thread should release a lock as many times as it acquires the lock.");
		} else {
			System.err.println("Property JavaMOP 2 satisfied");
		}
	}
}

error: pathspec 'code/qea/src/benchmark/competition/java/javaMOP/monitoring/JavaMOPTwoAspect.aj' did not match any file(s) known to git


add aspect for audit migrate-vm and add-disk

package org.ovirt.engine.core.bll;

import java.util.*;
import org.ovirt.engine.core.common.AuditLogType;
import org.ovirt.engine.core.bll.CommandActionState;

public privileged aspect Logs {
	AuditLogType around(org.ovirt.engine.core.bll.MigrateVmCommand command): execution(* getAuditLogTypeValue()) && this(command) {
		if (command.getSucceeded()
		 && command.isReturnValueUp())
			return AuditLogType.VM_MIGRATION_DONE;
		if (command.getSucceeded() && command.isInternalExecution()
		)
			return AuditLogType.VM_MIGRATION_START_SYSTEM_INITIATED;
		if (command.getSucceeded()
		)
			return AuditLogType.VM_MIGRATION_START;
		if (!command.getSucceeded()
		 && command.isHostInPrepareForMaintenance())
			return AuditLogType.VM_MIGRATION_FAILED_DURING_MOVE_TO_MAINTENANCE;
		if (!command.getSucceeded()
		)
			return AuditLogType.VM_MIGRATION_FAILED;
		return AuditLogType.UNASSIGNED;
	}

	AuditLogType around(org.ovirt.engine.core.bll.storage.disk.AddDiskCommand command): execution(* getAuditLogTypeValue()) && this(command) {
		if (command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE && command.isInternalExecution()
		 && command.isDiskStorageTypeRequiresExecuteState())
			return AuditLogType.ADD_DISK_INTERNAL;
		if (command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE
		 && command.isDiskStorageTypeRequiresExecuteState() && command.isVmNameExists())
			return AuditLogType.USER_ADD_DISK_TO_VM;
		if (command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE
		 && command.isDiskStorageTypeRequiresExecuteState())
			return AuditLogType.USER_ADD_DISK;
		if (!command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE && command.isInternalExecution()
		 && command.isDiskStorageTypeRequiresExecuteState())
			return AuditLogType.ADD_DISK_INTERNAL_FAILURE;
		if (!command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE
		 && command.isDiskStorageTypeRequiresExecuteState() && command.isVmNameExists())
			return AuditLogType.USER_FAILED_ADD_DISK_TO_VM;
		if (!command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE
		 && command.isDiskStorageTypeRequiresExecuteState())
			return AuditLogType.USER_FAILED_ADD_DISK;
		if (command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE
		 && command.isVmNameExists())
			return AuditLogType.USER_ADD_DISK_TO_VM_FINISHED_SUCCESS;
		if (command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE
		)
			return AuditLogType.USER_ADD_DISK_FINISHED_SUCCESS;
		if (!command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE
		 && command.isVmNameExists())
			return AuditLogType.USER_ADD_DISK_TO_VM_FINISHED_FAILURE;
		if (!command.getSucceeded() && command.getActionState() == CommandActionState.EXECUTE
		)
			return AuditLogType.USER_ADD_DISK_FINISHED_FAILURE;
		if (command.getSucceeded() && command.getActionState() == CommandActionState.END_SUCCESS
		 && command.isVmNameExists())
			return AuditLogType.USER_ADD_DISK_TO_VM_FINISHED_SUCCESS;
		if (command.getSucceeded() && command.getActionState() == CommandActionState.END_SUCCESS
		)
			return AuditLogType.USER_ADD_DISK_FINISHED_SUCCESS;
		if (!command.getSucceeded() && command.getActionState() == CommandActionState.END_SUCCESS
		 && command.isVmNameExists())
			return AuditLogType.USER_ADD_DISK_TO_VM_FINISHED_FAILURE;
		if (!command.getSucceeded() && command.getActionState() == CommandActionState.END_SUCCESS
		)
			return AuditLogType.USER_ADD_DISK_FINISHED_FAILURE;
		return AuditLogType.USER_ADD_DISK_FINISHED_FAILURE;
	}

}

error: pathspec 'backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/Logs.aj' did not match any file(s) known to git